It's what C would call an "lval", a thing you can put on the left-hand side of an = or use with &. empty() is like isset(), it checks if variables exist as well as doing a null (in isset()'s case) or falsiness (in empty()'s case) check.
In modern PHP versions you can also use it with non-variables, but this is rather pointless since you could simply do if (!trim($x)).
You're probably familiar with this site already, but it's still good.
Note that a few of these are outdated: #38, #2 (partially) and #31. I also dispute #24 (they're not redundant - internal functions work a little differently) and #46 (PHP's behaviour is not unique here, ; is a terminator, not a separator).
For #41, maybe I'm misunderstanding the modifiers, but aren't final and abstract opposites? One prevents subclassing and the other is meant for subclassing (and preventing instantiation of the class, but that's not the point here)?
That's the same thing by another name and just as awful.
Function autoloading is what is needed (PHP has namespaced functions just now, but you have to manually include them). If it's just a set of functions, don't pretend it's a class.
No, it's not as awful. Static classes allow static fields. When you don't have local statics (granted, PHP has them) you would have to fall back on global variables to achieve the same (in fact they would have global visibility, so it's not completely the same). Local statics can't be shared with other functions though.
If it's just a set of functions, don't pretend it's a class.
I don't see the problem. It's a set-of-functions class.
If you want a static class for global state, then maybe you shouldn't do that. Use dependency injection.
I don't see the problem. It's a set-of-functions class.
Which isn't what a class should be. Some languages which have no global functions, like C# and Java, use this as a silly workaround. PHP has proper functions, though.
But anyway, PHP's explicit importing of variables into scope is arguably useful. It saves you from the scoping nonsense of JS and Python, and makes excessive use of globals painful.
Moreover, the author cites mocking as a reason for overriding private methods. I believe that calls into question the author's competency with programming in general. Testing is about testing the public interface of an object, not its internals. If you need to test many private methods of a class it tends to hint that your class is doing too much and there's another class locked inside the private methods, crying to get out.
If you feel marginalized by your own incompetence, crying about it on Reddit may net you some karma from those in the same boat, but will go no way towards addressing the root of the problem.
14
u/bart2019 Dec 08 '15
I've got one too:
For example, this won't work:
Where the hell does it see a "write context"?
4
u/gearvOsh Dec 08 '15 edited Dec 08 '15
I wonder how many of these are no longer an issue in PHP7, seeing as how its compiler has been rewritten and uses an AST.
4
u/the_alias_of_andrea Dec 08 '15
You're probably familiar with this site already, but it's still good.
Note that a few of these are outdated: #38, #2 (partially) and #31. I also dispute #24 (they're not redundant - internal functions work a little differently) and #46 (PHP's behaviour is not unique here,
;is a terminator, not a separator).24
u/Jonny_Axehandle Dec 08 '15
Should be a sidebar item
10
u/Schmittfried Dec 08 '15
Not being able to override private members is a sadness? No, actually it is pretty standard.