2 ms·
Here's a pitfall I know from briefly trying to improve PHP, and having developed in it: The syntax definition is used for some types of basic type-checking. I
by TazeTSchnitzel 14y ago
Here's a pitfall I know from briefly trying to improve PHP, and having developed in it:
The syntax definition is used for some types of basic type-checking.
I'm completely serious.
Because of this, if you try to do a combination of property/array/etc. accesses that the grammar designers didn't envision, you'll get a very cryptic error. For example, this (which runs an anonymous function dereferenced from an array dereferencing from a static member of a class):
self::$views[$path]();
Doesn't work. It assumes that the result of self::$views[$path] is a string, and then complains there is no function with that name. (Yes, you can execute strings with names of functions, as if they were that function...) But this:
$x = self::$views[$path];
$x();
Does work.
Please, don't use PHP. It's horrible.
- lutusp 14y ago> Please, don't use PHP. It's horrible. I wish I could upvote this comment a dozen times, for a combination of candor and useful fact.
- meaty 14y agoInstantly invoking Godwin's law; knowing about the Nazis causes a moral shift towards making sure some horrible things don't happen again. The same applies to PHP. please do use it for a bit, learn about the crimes and don't repeat them :)
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- TazeTSchnitzel 14y agoParse error: syntax error, unexpected '[' in D:\Projects\2012\45blocks\45blocks\src\framework.php on line 18 No it doesn't.
- Udo 14y agoI'm sorry I deleted my post, didn't see your reply in time. $this->views[$path](); should not throw an error. What version are you using?
- TazeTSchnitzel 14y agoPHP 5.4. Let's try that code: Fatal error: Using $this when not in object context in D:\Projects\2012\45blocks\45blocks\src\framework.php on line 19 It's a static class member.
- Udo 14y agoYou're right, I didn't get that it doesn't work in a static context. I stand corrected, that definitely sucks.
- k3n 14y agoBecause all other languages are without problems.
- TazeTSchnitzel 14y agoPHP has more than its fair share.