symphonik Posted February 23, 2007 Share Posted February 23, 2007 Is it possible in PHP to overload the control structures themselves? Perhaps even this simpler case: say I wanted to create a NEW control structure to replicate Perl's "unless" control. If you're not familiar with Perl, unless is basically the same as if(!) -- my $var = 1; unless($var == 1) { print "Hello world"; } That snippet would print "Hello world" for any $var value EXCEPT 1. Could I go about replicating that in PHP? More generally, can I overload control structures in PHP? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 23, 2007 Share Posted February 23, 2007 I think you would have to do some "core hacking", as PHP only allows to to create functions and classes. Quote Link to comment Share on other sites More sharing options...
symphonik Posted February 23, 2007 Author Share Posted February 23, 2007 jesirose, that's kinda what I was worried about. I'm not against that for personal development, but that's obviously not sustainable for the systems I'm working on that will have to be maintained later. Ah well, it's just for syntactical bliss anyway. Not exactly a priority-one need. Thanks, jesirose. I'll keep paying attention in case anyone has any bright ideas, but this was the conclusion I needed verified. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.