cvs: ZendEngine2 / zend_compile.c php-src/tests/lang type_hints_002.phpt type_hints_003.phpt
| From: | Derick Rethans | Date: | Mon, 17 Oct 2005 07:03:35 +0000 |
| Subject: | cvs: ZendEngine2 / zend_compile.c php-src/tests/lang type_hints_002.phpt type_hints_003.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4250@lists.php.net to get a copy of this message | ||
derick Mon Oct 17 03:03:35 2005 EDT
Added files:
/php-src/tests/lang type_hints_002.phpt type_hints_003.phpt
Modified files:
/ZendEngine2 zend_compile.c
Log:
- Make sure that typehints for classes can only accept "= NULL" as default
value.
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.668&r2=1.669&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.668 ZendEngine2/zend_compile.c:1.669
--- ZendEngine2/zend_compile.c:1.668 Sat Oct 15 08:54:19 2005
+++ ZendEngine2/zend_compile.c Mon Oct 17 03:03:33 2005
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.668 2005/10/15 12:54:19 derick Exp $ */
+/* $Id: zend_compile.c,v 1.669 2005/10/17 07:03:33 derick Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -1332,12 +1332,20 @@
if (class_type->u.constant.type == IS_STRING || class_type->u.constant.type == IS_UNICODE)
{
cur_arg_info->class_name = Z_UNIVAL(class_type->u.constant);
cur_arg_info->class_name_len = Z_UNILEN(class_type->u.constant);
+
+ /* FIXME: make this work for unicode=on too */
+ if (op == ZEND_RECV_INIT) {
+ if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant)
== IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) {
+ cur_arg_info->allow_null = 1;
+ } else {
+ zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only
be NULL");
+ }
+ }
} else {
cur_arg_info->array_type_hint = 1;
cur_arg_info->class_name = NULL;
cur_arg_info->class_name_len = 0;
}
- cur_arg_info->allow_null = (op == ZEND_RECV_INIT &&
(Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant) ==
IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL")))) ? 1
: 0;
} else {
cur_arg_info->class_name = NULL;
cur_arg_info->class_name_len = 0;
http://cvs.php.net/co.php/php-src/tests/lang/type_hints_002.phpt?r=1.1&p=1
Index: php-src/tests/lang/type_hints_002.phpt
+++ php-src/tests/lang/type_hints_002.phpt
--TEST--
ZE2 type hinting
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<'))
die('skip ZendEngine 2 needed'); ?>
--FILE--
<?php
class P { }
class T {
function f(P $p = NULL) {
var_dump($p);
echo "-\n";
}
}
$o=new T();
$o->f(new P);
$o->f();
$o->f(NULL);
?>
--EXPECT--
object(P)#2 (0) {
}
-
NULL
-
NULL
-
http://cvs.php.net/co.php/php-src/tests/lang/type_hints_003.phpt?r=1.1&p=1
Index: php-src/tests/lang/type_hints_003.phpt
+++ php-src/tests/lang/type_hints_003.phpt
--TEST--
ZE2 type hinting
--SKIPIF--
<?php if (version_compare(zend_version(), '2.0.0-dev', '<'))
die('skip ZendEngine 2 needed'); ?>
--FILE--
<?php
class T {
function f(P $p = 42) {
}
}
?>
--EXPECTF--
Fatal error: Default value for parameters with a class type hint can only be NULL in %stest.php on
line 3