Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormsTest test fails when PHP is compiled in debug mode #1467

Closed
ghost opened this issue Oct 28, 2013 · 2 comments
Closed

FormsTest test fails when PHP is compiled in debug mode #1467

ghost opened this issue Oct 28, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 28, 2013

Testing FormsTest Not equals Phalcon\DI\FactoryDefault Object
(
    [_services:protected] => Array
        (
            [router] => Phalcon\DI\Service Object
                (
                    [_name:protected] => router
                    [_definition:protected] => Phalcon\Mvc\Router
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [dispatcher] => Phalcon\DI\Service Object
                (
                    [_name:protected] => dispatcher
                    [_definition:protected] => Phalcon\Mvc\Dispatcher
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [url] => Phalcon\DI\Service Object
                (
                    [_name:protected] => url
                    [_definition:protected] => Phalcon\Mvc\Url
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [modelsManager] => Phalcon\DI\Service Object
                (
                    [_name:protected] => modelsManager
                    [_definition:protected] => Phalcon\Mvc\Model\Manager
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [modelsMetadata] => Phalcon\DI\Service Object
                (
                    [_name:protected] => modelsMetadata
                    [_definition:protected] => Phalcon\Mvc\Model\MetaData\Memory
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [response] => Phalcon\DI\Service Object
                (
                    [_name:protected] => response
                    [_definition:protected] => Phalcon\Http\Response
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [cookies] => Phalcon\DI\Service Object
                (
                    [_name:protected] => cookies
                    [_definition:protected] => Phalcon\Http\Response\Cookies
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [request] => Phalcon\DI\Service Object
                (
                    [_name:protected] => request
                    [_definition:protected] => Phalcon\Http\Request
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [filter] => Phalcon\DI\Service Object
                (
                    [_name:protected] => filter
                    [_definition:protected] => Phalcon\Filter
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [escaper] => Phalcon\DI\Service Object
                (
                    [_name:protected] => escaper
                    [_definition:protected] => Phalcon\Escaper
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [security] => Phalcon\DI\Service Object
                (
                    [_name:protected] => security
                    [_definition:protected] => Phalcon\Security
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [crypt] => Phalcon\DI\Service Object
                (
                    [_name:protected] => crypt
                    [_definition:protected] => Phalcon\Crypt
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [annotations] => Phalcon\DI\Service Object
                (
                    [_name:protected] => annotations
                    [_definition:protected] => Phalcon\Annotations\Adapter\Memory
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [flash] => Phalcon\DI\Service Object
                (
                    [_name:protected] => flash
                    [_definition:protected] => Phalcon\Flash\Direct
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [flashSession] => Phalcon\DI\Service Object
                (
                    [_name:protected] => flashSession
                    [_definition:protected] => Phalcon\Flash\Session
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [tag] => Phalcon\DI\Service Object
                (
                    [_name:protected] => tag
                    [_definition:protected] => Phalcon\Tag
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [session] => Phalcon\DI\Service Object
                (
                    [_name:protected] => session
                    [_definition:protected] => Phalcon\Session\Adapter\Files
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [sessionBag] => Phalcon\DI\Service Object
                (
                    [_name:protected] => sessionBag
                    [_definition:protected] => Phalcon\Session\Bag
                    [_shared:protected] => 
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [eventsManager] => Phalcon\DI\Service Object
                (
                    [_name:protected] => eventsManager
                    [_definition:protected] => Phalcon\Events\Manager
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [transactionManager] => Phalcon\DI\Service Object
                (
                    [_name:protected] => transactions
                    [_definition:protected] => Phalcon\Mvc\Model\Transaction\Manager
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

            [assets] => Phalcon\DI\Service Object
                (
                    [_name:protected] => assets
                    [_definition:protected] => Phalcon\Assets\Manager
                    [_shared:protected] => 1
                    [_sharedInstance:protected] => 
                    [_resolved:protected] => 
                )

        )

    [_sharedInstances:protected] => 
    [_freshInstance:protected] => 
)
 != 
#0 /home/vladimir/workspace/cphalcon/unit-tests/FormsTest.php(143): PHPUnit_Framework_TestCase->assertEquals(Object(Phalcon\DI\FactoryDefault), NULL)
#1 /home/vladimir/workspace/cphalcon/unit-tests/manual-unit.php(133): FormsTest->testFormOptions()
#2 /home/vladimir/workspace/cphalcon/unit-tests/manual-unit.php(168): PHPUnit_Framework_TestCase::main('FormsTest')
#3 {main}
php: /home/vladimir/workspace/cphalcon/ext/phalcon.c:753: zm_deactivate_phalcon: Assertion `(*(((zend_phalcon_globals *) (*((void ***) tsrm_ls))[((phalcon_globals_id)-1)])->z_null)).type == 0' failed.
@ghost
Copy link
Author

ghost commented Oct 28, 2013

This is a very interesting bug and I wonder why we have not found it ages ago.

The test case is dead simple:

\Phalcon\Di::reset();
new \Phalcon\DI\FactoryDefault();

When Phalcon\DI\FactoryDefault was registered, Phalcon\DI's static properties were copied into it and made references. That is,

Phalcon\DI\FactoryDefault::_default = &Phalcon\DI::_default

Phalcon\Di::reset() sets Phalcon\Di::_default to PHALCON_GLOBAL(z_null). Then, when we create FactoryDefault, zend_update_class_constants is invoked. It then copies the values of all static properties from the parent class and makes them all references.

At this point PHALCON_GLOBAL(z_null) becomes a reference.

Then, when Phalcon\DI\FactoryDefault is instantiated, it calls

self::$_default = $this;

zend_update_static_property() sees that z_null is a reference and updates it with $this.

@ghost
Copy link
Author

ghost commented Oct 28, 2013

And because Travis PHP is built in release mode, main/php.h defines NDEBUG which effectively disables assert() and this is why there is no crash under Travis.

@ghost ghost mentioned this issue Oct 28, 2013
phalcon pushed a commit that referenced this issue Oct 29, 2013
@ghost ghost closed this as completed Oct 29, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants