Skip to content

Commit

Permalink
Merge pull request #1325 from sjinks/issue-1315
Browse files Browse the repository at this point in the history
Fix #1315
  • Loading branch information
Phalcon committed Oct 3, 2013
2 parents ade611e + ebf1cf7 commit 962531c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ext/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static int phalcon_config_count_elements(zval *object, long int *count TSRMLS_DC
static zval* phalcon_config_read_internal(phalcon_config_object *object, zval *key, int type TSRMLS_DC)
{
zval **retval;

if (UNEXPECTED(!key)) {
return EG(uninitialized_zval_ptr);
}
Expand All @@ -115,6 +116,10 @@ static zval* phalcon_config_read_property(zval *object, zval *offset, int type Z
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);

if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
if (BP_VAR_IS == type && !zend_get_std_object_handlers()->has_property(object, offset, 2 ZLK_CC TSRMLS_CC)) {
return EG(uninitialized_zval_ptr);
}

return zend_get_std_object_handlers()->read_property(object, offset, type ZLK_CC TSRMLS_CC);
}

Expand All @@ -129,6 +134,10 @@ static zval* phalcon_config_read_dimension(zval *object, zval *offset, int type
phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC);

if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) {
if (BP_VAR_IS == type && !zend_get_std_object_handlers()->has_dimension(object, offset, 0 TSRMLS_CC)) {
return EG(uninitialized_zval_ptr);
}

return zend_get_std_object_handlers()->read_dimension(object, offset, type TSRMLS_CC);
}

Expand Down
36 changes: 36 additions & 0 deletions ext/tests/issue-1315.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
--TEST--
\Phalcon\Config descendants throw E_NOTICE on access to a non existent element - https://github.com/phalcon/cphalcon/issues/1315
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
class C extends \Phalcon\Config {}

$c1 = new \Phalcon\Config();
$c2 = new C();

// Internal class, __isset/__get
var_dump(isset($c1->non->existing->value));
var_dump(empty($c1->non->existing->value));

// Internal class, offsetExists/offsetGet
var_dump(isset($c1['non']['existing']['value']));
var_dump(empty($c1['non']['existing']['value']));

// Userspace class, __isset/__get
var_dump(isset($c2->non->existing->value));
var_dump(empty($c2->non->existing->value));

// Userspace class, offsetExists/offsetGet
var_dump(isset($c2['non']['existing']['value']));
var_dump(empty($c2['non']['existing']['value']));
?>
--EXPECT--
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)

0 comments on commit 962531c

Please sign in to comment.