We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Strange warning, probably from zephir_fast_str_replace or something similar

Hello, i've following data:

0) Phalcon 2.0.8

1) Loader:

$loader->registerNamespaces([ 'Test\Module' => $config->modules, 'Test' => $config->common, ]);

2) Class:

namespace Test\Module\Matroshka\Demo{ class Module extends \Test\Module{ } }

3) Class:

namespace Test{ class Module{ } }

Issue: When i'm trying to execute code:

var_dump(class_exists('Test\Module\Matroshka\Demo\Module'));

i'm revieving an error

Warning: Invalid arguments supplied for str_replace() in D:\repository\test\application\modules\Matroshka\Demo\Module.php on line 5

Where "line 5" is:

class Module extends \Test\Module{

Any ideas how can i fix that meaningless warning. Though, seems everything is working, but i'll prefer to solve an issue. Thank you.

PS. if rename \Test\Module to \Test\Module2 and use it to extend classes then warning disappear.

edited Mar '16

Happened to me today, twice, with different classes. Still don't know what caused this, my current workaround is including the class file manually before using it. Renaming the class name or the file name didn't work. Would love to figure out how is trying to autoload classes related to str_replace.

Happened with phalcon 2.0.10 on both Ubuntu 15.10 and Debian stable, running with nginx.



5.4k

Phalcon 3.0.0, an issue yet exists

I found what is causing this issue and am leaving it here for anyone coming along with the same problem.

I've created a pull request (https://github.com/phalcon/cphalcon/pull/12684) to fix it.

While the pull is not accepted there is a way we can mitigate it by ordering all the keys of the namespace array that is sent to \Phalcon\Loader::registerNamespaces()

for example:

$loader = \Phalcon\Loader() $loader->registerNamespaces( $namespaces );

Should become

$loader = \Phalcon\Loader() uksort($namespaces, function($a, $b){ return strlen($a) > strlen($b); }); $loader->registerNamespaces( $namespaces );

Ordering the array keys by string size will make so that the loop inside \Phalcon\Loader::registerNamespaces() doesn't reach the point where it causes the Warning.

This is just a monkey patch and hopefully they will either accept the pull or mitigate the problem some other way.