4 ms·
I've used PHP a lot, work at a name-brand startup that uses a fair bit of PHP in the stack, and have an OSS PHP project I'm proud of (https://github.com/shaneha
by encoderer 14y ago
I've used PHP a lot, work at a name-brand startup that uses a fair bit of PHP in the stack, and have an OSS PHP project I'm proud of (https://github.com/shaneharter/PHP-Daemon https://github.com/shaneharter/PHP-Daemon). That is to say, I'm not a PHP hater. I see many flaws in the language, many many actually, but I'm not a hater.
But I really disagree with some of this.
First, why call variable references "pointers"? You're just breeding ignorance there. Understanding pointers is a valuable skill for a software engineer, even if they'll never use the skill directly in their day job as a PHP developer.
Second, you're introducing concepts that are a little sleazy like variable variables without any commentary on downsides or best practices. There is effectively nothing you can do with a variable variable that you cannot do with an associative array.
And fine, if you don't want to editorialize, if you want to just teach facts of the language without adding opinion, why invent the term "pointers" that, as far as I've ever read, is not used in any official PHP documentation.
- grakic 14y agoFor TimeClass one should not assume 86400 seconds in a day, and use DateTime::diff() instead. PHP The Right Way is better on this: http://www.phptherightway.com/#date_and_time http://www.phptherightway.com/#date_and_time With the autoloader, there is no need to do include_once(), simple include() is enough. The file will be loaded only once for every class.
- michaelmior 14y agoAgreed on some points. A mention of the serious trouble you can get in with variable variables is in order. I would never feel comfortable using user input to dictate a variable reference.
- FuzzyDunlop 14y agoI think it would have been worth pointing out the slightly more readable syntax for variable variables (and other metaprogramming features within PHP): ${$var}; ${$name.'Controller'}->function(); $something->{$functionName}(); With all the appropriate warnings, of course. For a start, don't find excuses to implement this style of code. You almost certainly don't need it for a basic website.
- juan_juarez 14y agoNearly any time you think "I need to have variable variable names", you should probably be using an array (dictionary, hash, whatever your language gives you). They're no more difficult to use & far harder to make horrible mistakes with.