5 ms·
Yay! <3 PHP. Also, the moment I read declare(strict_types..., for some reason "use strict"; from ECMAScript flashed in front of me :D
by awalGarg 12y ago
Yay! <3 PHP.
Also, the moment I read declare(strict_types..., for some reason "use strict"; from ECMAScript flashed in front of me :D
- some_furry 12y agoSame idea, except `use \Foo\Bar\Baz as SomeAlias` is already reserved for namespaces.
- TazeTSchnitzel 12y agoAlso, we already have use strict; as an easter egg ;)
- scintill76 12y agoExactly how do you trigger the easter egg, and what does it do?
- johnny22 12y ago$ php -a php > use strict; PHP Fatal error: You seem to be trying to use a different language... in php shell code on line 1
- some_furry 12y agoOkay, I have to admit, that is pretty amusing. :)
- tambourine_man 12y agoThat made my day, thanks
- awalGarg 12y agoOh my! That deserves another HN post in itself! <3
- TazeTSchnitzel 12y agoIf you say so! https://news.ycombinator.com/item?id=9219372 https://news.ycombinator.com/item?id=9219372
- Latty 12y agoThere are some similar gems to be found in Python: >>> from __future__ import braces File "<stdin>", line 1 SyntaxError: not a chance
- awalGarg 12y agoAlso try doing `import antigravity` from the Python repl ;)
- scintill76 12y agoThanks. I had tried it in 5.3 and only got the boring "The use statement with non-compound name 'strict' has no effect" error: http://3v4l.org/WY1Vs http://3v4l.org/WY1Vs
- deleted 12y ago[deleted]
- scintill76 12y ago"use strict"; (note 'use' is part of a string) should work in PHP for the same reason it does in ECMAScript -- it is a no-op at the language level (creating a string literal and doing nothing with it), that is unlikely to appear in old code, and can be given new meaning in the next-level language spec.
- chx 12y agoMaybe. But it means the parser now needs to "make sense" of strings whereas before it was just skipping over them.
- function_seven 12y agoNo it doesn't. The "use strict" declaration must occur before any other statements, allowing the parser to look specifically for those bytes, and treat it as a separate token instead of as a string. It doesn't have to inspect the contents of all strings.
- ircmaxell 12y agoWe looked into using it. After much thought, we decided not to, here's why: https://wiki.php.net/rfc/scalar_type_hints_v5#why_not_use_use_strict_instead_of_declare https://wiki.php.net/rfc/scalar_type_hints_v5#why_not_use_us... I break down all of the proposed alternatives and the cases against them.