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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.