From: Antony Dovgal Date: Thu, 7 Jun 2007 08:37:40 +0000 (+0000) Subject: MFH: change E_NOTICE to E_ERROR when using a class constant from non-existent class X-Git-Tag: php-5.2.4RC1~390 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91da96ba71867b72278aeb4d6deaff334c7f3771;p=php MFH: change E_NOTICE to E_ERROR when using a class constant from non-existent class (noticed by Jani) add tests --- diff --git a/Zend/tests/class_constants_001.phpt b/Zend/tests/class_constants_001.phpt new file mode 100644 index 0000000000..45270f6f73 --- /dev/null +++ b/Zend/tests/class_constants_001.phpt @@ -0,0 +1,22 @@ +--TEST-- +class constants basic tests +--FILE-- + +--EXPECTF-- +string(6) "string" +int(1) + +Fatal error: Undefined class constant 'val3' in %s on line %d diff --git a/Zend/tests/class_constants_002.phpt b/Zend/tests/class_constants_002.phpt new file mode 100644 index 0000000000..9aad8088da --- /dev/null +++ b/Zend/tests/class_constants_002.phpt @@ -0,0 +1,31 @@ +--TEST-- +class constants as default function arguments +--FILE-- + +--EXPECTF-- +int(1) +int(5) +int(10) + +Fatal error: Class 'NoSuchClass' not found in %s on line %d diff --git a/Zend/tests/class_constants_003.phpt b/Zend/tests/class_constants_003.phpt new file mode 100644 index 0000000000..c2782ff1c9 --- /dev/null +++ b/Zend/tests/class_constants_003.phpt @@ -0,0 +1,33 @@ +--TEST-- +class constants as default function arguments and dynamically loaded classes +--FILE-- + +DATA; + +$filename = dirname(__FILE__)."/cc003.dat"; +file_put_contents($filename, $class_data); + +function foo($v = test::val) { + var_dump($v); +} + +include $filename; + +foo(); +foo(5); + +unlink($filename); + +echo "Done\n"; +?> +--EXPECTF-- +int(1) +int(5) +Done diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c index 9fe79d4d97..ab0c1c5122 100644 --- a/Zend/zend_constants.c +++ b/Zend/zend_constants.c @@ -259,15 +259,16 @@ ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_ retval = 0; } } - efree(class_name); if (retval && ce) { if (zend_hash_find(&((*ce)->constants_table), constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) { retval = 0; } } else { + zend_error(E_ERROR, "Class '%s' not found", class_name); retval = 0; } + efree(class_name); if (retval) { zval_update_constant(ret_constant, (void*)1 TSRMLS_CC);