PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi...
I've been struggling to find a solution to a situation that has me stumped.
The application I am developing needs to store 'rules' in a database that are then evaluated within the code.
(i.e. the user can write custom rules)
What i want to do is this:
if ($rule){Do something}
Where $rule is an if condition that I retrieve from the database and will look something like this - i.e. ' $this->status=="valid" and ($otherObj->emailsend=="yes" or $this->post=="yes") '
I tried it in test code (below), (at least how I [i]hoped[/i] it would work), but it always returns 'pending':
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
In your code as it stands $x is just a string. If you do if($x){ it'll be basically the same as saying if(isset($x)){ ... which is true. You'll need to use eval() (lazy, potential security hole), or write a system that stores the rules in your own syntax and a little parser to turn them into something that can be evaluated (tricky, but cool if done right).
You are right about security, although in this case the rules can only be written by the Admin user, and will be validated before entry into database, (i.e. check valid options, remove quotes etc.), so I think I can get away without writing my own parser.
You are right about security, although in this case the rules can only be written by the Admin user, and will be validated before entry into database, (i.e. check valid options, remove quotes etc.), so I think I can get away without writing my own parser.