]> granicus.if.org Git - php/commitdiff
change E_NOTICE to E_ERROR when using a class constant from non-existent class
authorAntony Dovgal <tony2001@php.net>
Mon, 4 Jun 2007 08:24:32 +0000 (08:24 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 4 Jun 2007 08:24:32 +0000 (08:24 +0000)
(noticed by Jani)
add tests

Zend/tests/class_constants_001.phpt [new file with mode: 0644]
Zend/tests/class_constants_002.phpt [new file with mode: 0644]
Zend/tests/class_constants_003.phpt [new file with mode: 0644]
Zend/zend_constants.c

diff --git a/Zend/tests/class_constants_001.phpt b/Zend/tests/class_constants_001.phpt
new file mode 100644 (file)
index 0000000..f2c3b3e
--- /dev/null
@@ -0,0 +1,27 @@
+--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
+--UEXPECTF--
+unicode(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 (file)
index 0000000..9aad808
--- /dev/null
@@ -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
diff --git a/Zend/tests/class_constants_003.phpt b/Zend/tests/class_constants_003.phpt
new file mode 100644 (file)
index 0000000..c2782ff
--- /dev/null
@@ -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
index 1050ddb8eecf4196960f1f418c1f06dc756490a1..1a2ffc2e2589365cd6d6f982b8d0331a36aa5416 100644 (file)
@@ -318,15 +318,16 @@ ZEND_API int zend_u_get_constant(zend_uchar type, zstr name, uint name_len, zval
                                retval = 0;
                        }
                }
-               efree(class_name.v);
 
                if (retval && ce) {
                        if (zend_u_hash_find(&((*ce)->constants_table), type, constant_name, const_name_len+1, (void **) &ret_constant) != SUCCESS) {
                                retval = 0;
                        }
                } else {
+                       zend_error(E_ERROR, "Class '%R' not found", type, class_name);
                        retval = 0;
                }
+               efree(class_name.v);
 
                if (retval) {
                        zval_update_constant(ret_constant, (void*)1 TSRMLS_CC);