Closed dustinpaluch closed 2 years ago
The default REPL uses PHP eval()
to execute the code, and eval()
does not work properly with namespaces, a limitation in PHP itself.
If you want to use namespaces in wp shell
, you install the additional PsySH
REPL, which provides many improvements, one of them being support for namespaces.
One easy way to do so is through the package manager:
wp package install schlessera/wp-cli-psysh
Shouldn't this fail then, from php --interactive
?
php > eval('namespace dustinpaluch { function foobar() { echo __FUNCTION__; } foobar(); }');
dustinpaluch\foobar
Looks like my code doesn't work in 5.2.x, but starts working in 5.3.x.
I'm trying to reproduce a bug involving namespaces, wp actions, and anonymous functions, and was hoping I'd be able to use the wp shell to make a minimal test case.