3 ms·
The far greater wart is passing functions as string names. PHP is so bad that it's hard to imagine that it isn't a giant troll. No amount of modernizing will ev
by jules 12y ago
The far greater wart is passing functions as string names. PHP is so bad that it's hard to imagine that it isn't a giant troll. No amount of modernizing will ever turn PHP into anything close to sane; the amount and depth of craziness is simply too huge.
- TazeTSchnitzel 12y agoThat's something I'm working on by adding function references. Not sure if it'll be accepted.
- donatj 12y agoI feel like its callable system is simple, easy to use, and frankly awesome. I can do $func = ['object', 'staticMethodName']; $func = [$instance, 'publicMethodName']; $func = 'functionName'; $func = '\namespaced\functionName'; $func = function(){ ... }; $func = $callableObject; // ( http://php.net/manual/en/language.oop5.overloading.php#object.call http://php.net/manual/en/language.oop5.overloading.php#objec... ) I can execute any of the above by calling `$func('doIt');` Moreover all of those will all pass a `callable` typehint on a method call as well as the is_callable if they exist and are callable. Its quite powerful.
- jules 12y agoThe problem is that a function is a thing. A string is a different thing. Imagine if arrays were represented as comma delimited strings, and you had a function isArray to check if a string has the right format to represent an array. That would be ridiculous right? An array should be its own type. The same goes for functions. Representing functions as string names is just as crazy as representing arrays as comma delimited strings. Though who am I kidding, PHP is also confused between numbers and arrays and strings, so I guess at least it's consistent that the language is thoroughly crazy.
- skybrian 12y agoRidiculous or not, Tcl works like this. Everything is a string.
- wvenable 12y agoA lot of languages have ways of calling functions and methods by string names -- PHP just makes it very easy and the design is actually really clean.
- chriswarbo 12y ago> PHP just makes it very easy and the design is actually really clean. Very little about PHP's treatment of functions is easy or clean. function foo() { echo "Hello world"; } $w = 'foo'; echo $w; // foo $w(); // Hello world 'foo'(); // PHP Parse error: syntax error, unexpected '(' function bar() { return 'foo'; } $x = bar(); echo $x; // foo $x(); // Hello world bar()(); // PHP Parse error: syntax error, unexpected '(' $o = new stdClass; $o->baz = 'foo'; $y = $o->baz; echo $y; // foo $y(); // Hello world $o->baz(); // PHP Fatal error: Call to undefined method stdClass::baz() Heck, PHP doesn't even recognise function-call syntax applied to a function! $z = function() { echo "Hello world"; }; $z(); // Hello world (function() { echo "Hello world"; })(); // PHP Parse error: syntax error, unexpected '('
- wvenable 12y agoWhen this[1] RFC goes through most of those issues will be resolved. Even without them, ignoring edge cases ('foo'() isn't useful), it's still quite reasonable. The RFC linked above just improves on the design, it doesn't change it. [1] https://wiki.php.net/rfc/uniform_variable_syntax https://wiki.php.net/rfc/uniform_variable_syntax