mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
MFH: change E_NOTICE to E_ERROR when using a class constant from non-existent class
(noticed by Jani) add tests
This commit is contained in:
parent
20b5c66e14
commit
91da96ba71
22
Zend/tests/class_constants_001.phpt
Normal file
22
Zend/tests/class_constants_001.phpt
Normal file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
class constants basic tests
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class test {
|
||||
const val = "string";
|
||||
const val2 = 1;
|
||||
}
|
||||
|
||||
var_dump(test::val);
|
||||
var_dump(test::val2);
|
||||
|
||||
var_dump(test::val3);
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(6) "string"
|
||||
int(1)
|
||||
|
||||
Fatal error: Undefined class constant 'val3' in %s on line %d
|
31
Zend/tests/class_constants_002.phpt
Normal file
31
Zend/tests/class_constants_002.phpt
Normal file
@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
class constants as default function arguments
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class test {
|
||||
const val = 1;
|
||||
}
|
||||
|
||||
function foo($v = test::val) {
|
||||
var_dump($v);
|
||||
}
|
||||
|
||||
function bar($b = NoSuchClass::val) {
|
||||
var_dump($b);
|
||||
}
|
||||
|
||||
foo();
|
||||
foo(5);
|
||||
|
||||
bar(10);
|
||||
bar();
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
int(1)
|
||||
int(5)
|
||||
int(10)
|
||||
|
||||
Fatal error: Class 'NoSuchClass' not found in %s on line %d
|
33
Zend/tests/class_constants_003.phpt
Normal file
33
Zend/tests/class_constants_003.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
class constants as default function arguments and dynamically loaded classes
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$class_data = <<<DATA
|
||||
<?php
|
||||
class test {
|
||||
const val = 1;
|
||||
}
|
||||
?>
|
||||
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
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user