Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Same idea, except `use \Foo\Bar\Baz as SomeAlias` is already reserved for namespaces.


Also, we already have use strict; as an easter egg ;)


Exactly how do you trigger the easter egg, and what does it do?


$ 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


There are some similar gems to be found in Python:

    >>> from __future__ import braces
      File "<stdin>", line 1
    SyntaxError: not a chance


Also try doing `import antigravity` from the Python repl ;)


Okay, I have to admit, that is pretty amusing. :)


That made my day, thanks


Oh my! That deserves another HN post in itself! <3



Thanks. 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


    "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.


Maybe. But it means the parser now needs to "make sense" of strings whereas before it was just skipping over them.


No 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: