]> granicus.if.org Git - php/commitdiff
- Allow "= null" default for parameters with a class type-hint.
authorDerick Rethans <derick@php.net>
Tue, 15 Nov 2005 15:59:49 +0000 (15:59 +0000)
committerDerick Rethans <derick@php.net>
Tue, 15 Nov 2005 15:59:49 +0000 (15:59 +0000)
NEWS
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 565b22fcf6366b9f27779a28606172255df05622..33116db0666f8da24f29f4595f92e9c9ffbb4f97 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Nov 2005, PHP 5.1
 - Allow recursive calls to __get/__set for different properties. (Dmitry)
+- Allow "= null" default for parameters with a class type-hint. (Derick)
 - Upgraded PEAR to version 1.4.4. (Greg)
 - Fixed bug in mysqli extension with unsigned int(11) being represented as 
   signed integer in PHP instead of string in 32bit systems. (Andrey)
index decfaa7b2451de9eaa0cd8d95804898478eabf5c..c10f694ee1cea86a6df676dcb307aa1f52e72b09 100644 (file)
@@ -1273,15 +1273,23 @@ void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initia
        cur_arg_info->pass_by_reference = pass_by_reference;
 
        if (class_type->op_type != IS_UNUSED) {
+               cur_arg_info->allow_null = 0;
                if (class_type->u.constant.type == IS_STRING) {
                        cur_arg_info->class_name = class_type->u.constant.value.str.val;
                        cur_arg_info->class_name_len = class_type->u.constant.value.str.len;
+
+                       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 = 0;
        } else {
                cur_arg_info->class_name = NULL;
                cur_arg_info->class_name_len = 0;