Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_constants.c /tests class_constants_001.phpt class_constants_002.phpt class_constants_003.phpt
| From: | Jani Taskinen | Date: | Mon, 04 Jun 2007 08:38:29 +0000 |
| Subject: | Re: [ZEND-ENGINE-CVS] cvs: ZendEngine2 / zend_constants.c /tests class_constants_001.phpt class_constants_002.phpt class_constants_003.phpt | ||
| References: | 1 | Groups: | php.zend-engine.cvs |
| Request: | Send a blank email to php-zend-engine-cvs+get-5830@lists.php.net to get a copy of this message | ||
MFH? This is a fix after all..
--Jani
On Mon, 2007-06-04 at 08:24 +0000, Antony Dovgal wrote:
> tony2001 Mon Jun 4 08:24:32 2007 UTC
>
> Added files:
> /ZendEngine2/tests class_constants_001.phpt
> class_constants_002.phpt
> class_constants_003.phpt
>
> Modified files:
> /ZendEngine2 zend_constants.c
> Log:
> change E_NOTICE to E_ERROR when using a class constant from non-existent class
> (noticed by Jani)
> add tests
>
>
>
> http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_constants.c?r1=1.90&r2=1.91&diff_format=u
> Index: ZendEngine2/zend_constants.c
> diff -u ZendEngine2/zend_constants.c:1.90 ZendEngine2/zend_constants.c:1.91
> --- ZendEngine2/zend_constants.c:1.90 Mon Jan 1 09:29:20 2007
> +++ ZendEngine2/zend_constants.c Mon Jun 4 08:24:32 2007
> @@ -17,7 +17,7 @@
> +----------------------------------------------------------------------+
> */
>
> -/* $Id: zend_constants.c,v 1.90 2007/01/01 09:29:20 sebastian Exp $ */
> +/* $Id: zend_constants.c,v 1.91 2007/06/04 08:24:32 tony2001 Exp $ */
>
> #include "zend.h"
> #include "zend_constants.h"
> @@ -318,15 +318,16 @@
> 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);
>
>
> http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/class_constants_001.phpt?view=markup&rev=1.1
> Index: ZendEngine2/tests/class_constants_001.phpt
> +++ ZendEngine2/tests/class_constants_001.phpt
> --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
>
>
> http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/class_constants_002.phpt?view=markup&rev=1.1
> Index: ZendEngine2/tests/class_constants_002.phpt
> +++ ZendEngine2/tests/class_constants_002.phpt
> --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
>
>
> http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/class_constants_003.phpt?view=markup&rev=1.1
> Index: ZendEngine2/tests/class_constants_003.phpt
> +++ ZendEngine2/tests/class_constants_003.phpt
> --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
>