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

[1.2.4] Fix #1277 (ability to clone \Phalcon\Config) #1278

Merged
merged 2 commits into from Sep 23, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #1277
  • Loading branch information
sjinks committed Sep 23, 2013
commit 216e703e5d4612fb3c9327008bcacb611ba94590
18 changes: 16 additions & 2 deletions ext/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static void phalcon_config_object_dtor(void* v TSRMLS_DC)
*/
static zend_object_value phalcon_config_object_ctor(zend_class_entry* ce TSRMLS_DC)
{
phalcon_config_object* obj = ecalloc(1, sizeof(phalcon_config_object));
phalcon_config_object *obj = ecalloc(1, sizeof(phalcon_config_object));
zend_object_value retval;

zend_object_std_init(&obj->obj, ce TSRMLS_CC);
Expand All @@ -334,14 +334,27 @@ static zend_object_value phalcon_config_object_ctor(zend_class_entry* ce TSRMLS_
obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
phalcon_config_object_dtor,
NULL TSRMLS_CC
NULL
TSRMLS_CC
);

retval.handlers = &phalcon_config_object_handlers;

return retval;
}

static zend_object_value phalcon_config_clone_obj(zval *object TSRMLS_DC)
{
phalcon_config_object *orig = fetchPhalconConfigObject(object TSRMLS_CC);
zend_object_value result = phalcon_config_object_ctor(Z_OBJCE_P(object) TSRMLS_CC);
phalcon_config_object *clone = zend_object_store_get_object_by_handle(result.handle TSRMLS_CC);

zend_objects_clone_members(&clone->obj, result, &orig->obj, Z_OBJ_HANDLE_P(object) TSRMLS_CC);
zend_hash_copy(clone->props, orig->props, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));

return result;
}

/**
* Phalcon\Config initializer
*/
Expand All @@ -363,6 +376,7 @@ PHALCON_INIT_CLASS(Phalcon_Config){
phalcon_config_object_handlers.has_dimension = phalcon_config_has_dimension;
phalcon_config_object_handlers.get_properties = phalcon_config_get_properties;
phalcon_config_object_handlers.compare_objects = phalcon_config_compare_objects;
phalcon_config_object_handlers.clone_obj = phalcon_config_clone_obj;

zend_class_implements(phalcon_config_ce TSRMLS_CC, 2, zend_ce_arrayaccess, spl_ce_Countable);

Expand Down
21 changes: 21 additions & 0 deletions ext/tests/issue-1277.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Phalcon\Config after clone is empty - https://github.com/phalcon/cphalcon/issues/1277
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
$c1 = new Phalcon\Config();
$c1["test"] = 1;
$c2 = clone $c1;
var_dump($c1);
var_dump($c2);
?>
--EXPECT--
object(Phalcon\Config)#1 (1) {
["test"]=>
int(1)
}
object(Phalcon\Config)#2 (1) {
["test"]=>
int(1)
}