Jump to content

Overload control structures? (i.e. if/else/etc)


symphonik

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/39841-overload-control-structures-ie-ifelseetc/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.