Hello there.
I have seen an implementation of nodejs’ require function - but it needed to use a variable-function ($require(string $name)) instead, because ‚require()‘ is given.
My questions are:
- Why is require still also available as a function?
- Why can’t re re-define something like that?
Kind regards, and thanks! ^^
Hi,
On Mon, Dec 23, 2013 at 8:28 AM, Kevin Ingwersen
ingwie2000@googlemail.comwrote:
Hello there.
I have seen an implementation of nodejs’ require function - but it needed
to use a variable-function ($require(string $name)) instead, because
‚require()‘ is given.My questions are:
- Why is require still also available as a function?
- Why can’t re re-define something like that?
This is because require
is not a function but a language construct; the
token is defined in the language parser definition:
http://lxr.php.net/xref/PHP_5_6/Zend/zend_language_parser.y#62
Because of this, require
is a reserved word unless exceptions are made in
the parser itself, so class require
and function require()
, even when
defined inside your own namespace will cause a parse error.
Kind regards, and thanks! ^^
--
Tjerk