cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[BUG] Double inclusion of module file

Open beermeat opened this issue 13 years ago • 7 comments

simple multimodule app:

$application = new Application($di);

// Register the installed modules
$application->registerModules(array(
    'default' => array(
        'className' => 'Multiple\Frontend\Module',
        'path'      => '../apps/frontend/Module.php',
    )
));

call handle:

echo $application->handle('/foo/bar/')->getContent();

its ok.

then make a second call:

echo $application->handle('/bla/bla/')->getContent();

oops, an error:

Fatal error: Cannot redeclare class Module in apps/frontend/Module.php on line 6

phalcon 1.2

beermeat avatar Jul 09 '13 15:07 beermeat

Confirmed, the bug is caused by phalcon_require:

            if (phalcon_array_isset_string(module, SS("path"))) {

                PHALCON_OBS_VAR(path);
                phalcon_array_fetch_string(&path, module, SL("path"), PH_NOISY_CC);
                if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) {
                    if (phalcon_require(path TSRMLS_CC) == FAILURE) {
                        return;
                    }
                } else {
                    PHALCON_INIT_NVAR(exception_msg);
                    PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "' doesn't exist");
                    PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_application_exception_ce, exception_msg);
                    return;
                }
            }

A quick workaround:

if (!class_exists('Module')) :

class Module { /* your code here */ }

endif;

ghost avatar Jul 09 '13 17:07 ghost

thanks!

beermeat avatar Jul 11 '13 08:07 beermeat

it's incredible, but the bug remains :( phalcon 1.2.1

beermeat avatar Jul 11 '13 20:07 beermeat

Can you please compile from the ext/ directory?

cd cphalcon/ext
sudo ./install

ghost avatar Jul 11 '13 20:07 ghost

Unable to reproduce with 412289eeb22e143d9798db39bbcc3f1880331baf

ghost avatar Jul 11 '13 21:07 ghost

yes, sorry, from the ext/ directory all works fine

beermeat avatar Jul 12 '13 06:07 beermeat

This bug is still present in 1.2.5

When forwarding a CLI call and defining the (same) module:

$this->application->handle(array(
    'module' => 'api',
    'task' => 'main',
    'action' => 'foobar'
));

The module bootstrap is included a second time:

Fatal error: Cannot redeclare class MyApp\Api\Module in /www/myapp/application/modules/api/Module.php on line 10

fabfuel avatar Jan 26 '14 18:01 fabfuel