Implementing callbacks -- which do you prefer
Posted: Wed Aug 13, 2008 8:01 pm
Seeing as this is for an (eventual) open source project...I'd like personal opinions or constructive criticism why one method is prefered over the other...
Example 1:
Example 2:
Personally I don't mind either and maybe even prefer Example 2 BUT...I can see the code being confusing to someone just visiting the first time especially if they are not overly familiar with PHP and it's dynamic nature...whereas if I used a call_user_* approach...when they seen that code they would at least have the PHP docs to lookup and quickly determine what it was the code was doing.
Also I would think it might have the additional advantage of increased performance as the additional tokenizing/parsing would likely be required to support the more runtime dynamic approach of Example 2...but who knows I'm not about to profile for something so trivial.
What do you prefer?
Example 1:
Code: Select all
call_user_func_array('my_method', $args)Code: Select all
$func = 'my_method';
$func($args);Also I would think it might have the additional advantage of increased performance as the additional tokenizing/parsing would likely be required to support the more runtime dynamic approach of Example 2...but who knows I'm not about to profile for something so trivial.
What do you prefer?