From b6e3e908f35ef171b7d507708f250bbfbafe9785 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 5 Dec 2013 04:01:05 +0200 Subject: [PATCH 1/3] Test case for #1637 --- ext/tests/issue-1637.phpt | 120 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 ext/tests/issue-1637.phpt diff --git a/ext/tests/issue-1637.phpt b/ext/tests/issue-1637.phpt new file mode 100644 index 00000000000..fcafac0a066 --- /dev/null +++ b/ext/tests/issue-1637.phpt @@ -0,0 +1,120 @@ +--TEST-- +Cannot Remove A Property From Phalcon Persistent Storage - https://github.com/phalcon/cphalcon/issues/1637 +--SKIPIF-- + +--GET-- +dummy=1 +--FILE-- +persistent->destroy(); + $this->dump('anu'); + echo "Set\n"; + $this->persistent->anu = 'Aloha'; + $this->dump('anu'); + echo "Remove\n"; + $this->persistent->remove('anu'); + $this->dump('anu'); + echo "set\n"; + $this->persistent->anu = 'Aloha'; + $this->dump('anu'); + echo "assign null\n"; + $this->persistent->anu = null; + $this->dump('anu'); + echo "set\n"; + $this->persistent->anu = 'Aloha'; + $this->dump('anu'); + echo "destroy\n"; + $this->persistent->destroy(); + $this->dump('anu'); + } + + public function dump($v) + { + echo $v, '=', var_dump($this->persistent->$v); + echo 'has(', $v, ')=', var_dump($this->persistent->has($v)); + echo 'isset(', $v, ')=', var_dump(isset($this->persistent->$v)); + echo PHP_EOL; + } +} + +$di = new \Phalcon\DI\FactoryDefault(); +$di['session'] = function() { $s = new \Phalcon\Session\Adapter\Files(array('uniqueId' => 'issue-1575')); $s->start(); return $s; }; + +$test = new Test(); +$test->test(); + +?> +--EXPECT-- +anu=NULL +has(anu)=bool(false) +isset(anu)=bool(false) + +Set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +Remove +anu=NULL +has(anu)=bool(false) +isset(anu)=bool(false) + +set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +assign null +anu=NULL +has(anu)=bool(true) +isset(anu)=bool(true) + +set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +destroy +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +Set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +Remove +anu=NULL +has(anu)=bool(false) +isset(anu)=bool(false) + +set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +assign null +anu=NULL +has(anu)=bool(true) +isset(anu)=bool(true) + +set +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + +destroy +anu=string(5) "Aloha" +has(anu)=bool(true) +isset(anu)=bool(true) + From 4807e84640b74873e36efc0eab690bbd6cbe0387 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 5 Dec 2013 04:03:58 +0200 Subject: [PATCH 2/3] Use zend_update_property for dynamic properties Fix #1637 --- ext/di/injectable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/di/injectable.c b/ext/di/injectable.c index 1197fe97f46..d0b305b8c3d 100644 --- a/ext/di/injectable.c +++ b/ext/di/injectable.c @@ -182,7 +182,7 @@ PHP_METHOD(Phalcon_DI_Injectable, __get){ ZVAL_STRING(service, "sessionBag", 1); phalcon_return_call_method_p2(dependency_injector, "get", service, arguments); - phalcon_update_property_this(this_ptr, SL("persistent"), (return_value_ptr ? *return_value_ptr : return_value) TSRMLS_CC); + zend_update_property(phalcon_di_injectable_ce, getThis(), SL("persistent"), (return_value_ptr ? *return_value_ptr : return_value) TSRMLS_CC); RETURN_MM(); } From 11001ae2428d24be1497e7eb4beaf06302502f03 Mon Sep 17 00:00:00 2001 From: Vladimir Kolesnikov Date: Thu, 5 Dec 2013 04:11:33 +0200 Subject: [PATCH 3/3] Phalcon\Session\Bag fixes * initalized => initialized * add initialization check to remove() * be less aggressive in __construct() --- ext/session/bag.c | 58 ++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/ext/session/bag.c b/ext/session/bag.c index 82a9b1eb2d9..dc5a59643ab 100644 --- a/ext/session/bag.c +++ b/ext/session/bag.c @@ -62,7 +62,7 @@ PHALCON_INIT_CLASS(Phalcon_Session_Bag){ zend_declare_property_null(phalcon_session_bag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_session_bag_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_session_bag_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_session_bag_ce, SL("_initalized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_session_bag_ce, SL("_initialized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(phalcon_session_bag_ce, SL("_session"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_class_implements(phalcon_session_bag_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_session_baginterface_ce); @@ -77,16 +77,11 @@ PHALCON_INIT_CLASS(Phalcon_Session_Bag){ */ PHP_METHOD(Phalcon_Session_Bag, __construct){ - zval *name; + zval **name; - phalcon_fetch_params(0, 1, 0, &name); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The name parameter must be a string"); - return; - } - phalcon_update_property_this(this_ptr, SL("_name"), name TSRMLS_CC); - + phalcon_fetch_params_ex(1, 0, &name); + PHALCON_ENSURE_IS_STRING(name); + phalcon_update_property_this(this_ptr, SL("_name"), *name TSRMLS_CC); } /** @@ -161,7 +156,7 @@ PHP_METHOD(Phalcon_Session_Bag, initialize){ } phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_initalized"), 1 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_initialized"), 1 TSRMLS_CC); PHALCON_MM_RESTORE(); } @@ -175,13 +170,13 @@ PHP_METHOD(Phalcon_Session_Bag, initialize){ */ PHP_METHOD(Phalcon_Session_Bag, destroy){ - zval *initalized, *name, *session; + zval *initialized, *name, *session; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + if (PHALCON_IS_FALSE(initialized)) { phalcon_call_method_noret(this_ptr, "initialize"); } @@ -207,16 +202,16 @@ PHP_METHOD(Phalcon_Session_Bag, destroy){ */ PHP_METHOD(Phalcon_Session_Bag, set){ - zval *property, *value, *initalized, *name, *data; + zval *property, *value, *initialized, *name, *data; zval *session; PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &property, &value); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + if (PHALCON_IS_FALSE(initialized)) { phalcon_call_method_noret(this_ptr, "initialize"); } @@ -261,7 +256,7 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __set); */ PHP_METHOD(Phalcon_Session_Bag, get){ - zval *property, *default_value = NULL, *initalized; + zval *property, *default_value = NULL, *initialized; zval *data, *value; PHALCON_MM_GROW(); @@ -275,9 +270,9 @@ PHP_METHOD(Phalcon_Session_Bag, get){ /** * Check first if the bag is initialized */ - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + if (PHALCON_IS_FALSE(initialized)) { phalcon_call_method_noret(this_ptr, "initialize"); } @@ -323,15 +318,15 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __get); */ PHP_METHOD(Phalcon_Session_Bag, has){ - zval *property, *initalized, *data; + zval *property, *initialized, *data; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &property); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this(&initalized, this_ptr, SL("_initalized"), PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + if (PHALCON_IS_FALSE(initialized)) { phalcon_call_method_noret(this_ptr, "initialize"); } @@ -370,11 +365,18 @@ PHALCON_DOC_METHOD(Phalcon_Session_Bag, __isset); PHP_METHOD(Phalcon_Session_Bag, remove){ zval *property, *data = NULL, *name, *session; + zval *initialized; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &property); - + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this(&initialized, this_ptr, SL("_initialized"), PH_NOISY_CC); + if (PHALCON_IS_FALSE(initialized)) { + phalcon_call_method_noret(this_ptr, "initialize"); + } + PHALCON_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (phalcon_array_isset(data, property)) {