Domanda

Should the following problem be considered normal behavior or a bug?

<?php
namespace Ns;

function func ()
{
    echo "Hello\n";
    return true;
}

func(); // ok
assert('func()'); // "Call to undefined function func()"
È stato utile?

Soluzione

assert I assume is behaving the same way as eval does in that it switches execution to the global namespace when the code passed to it is evaluated. Specifying the namespace in the call works as you would expect:

<?php
namespace Ns;

function func ()
{
    echo "Hello\n";
    return true;
}

func(); // ok
assert('Ns\func()');

I would believe this to be normal behavior; assert is a built in function, and you're basically passing a string to it to be evaluated. When execution passes to inside of the assert function, it would be in a completely different namespace (mainly the global namespace).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top