Index: Zend/ZEND_CHANGES =================================================================== RCS file: /repository/ZendEngine2/ZEND_CHANGES,v retrieving revision 1.55 diff -u -r1.55 ZEND_CHANGES --- Zend/ZEND_CHANGES 7 Mar 2003 16:45:41 -0000 1.55 +++ Zend/ZEND_CHANGES 28 Mar 2003 17:09:53 -0000 @@ -177,6 +177,10 @@ function b(Bar $bar) { // ... } + + function c([Bar] $bar) { + // ... + } } $a = new FooBar; @@ -184,10 +188,14 @@ $a->a($b); $a->b($b); + $a->c($b); + $a->c(NULL); ?> These class type hints are not checked upon compilation, as would - be the case in a typed language, but during runtime. + be the case in a typed language, but during runtime. Type hints in + square brackets (as seen in function "c") denote passing of NULL is + also allowed. This means that @@ -202,6 +210,21 @@ die('Argument 1 must be an instance of ClassName'); } } + + and + + function foo([ClassName] $object) { + // ... + } + + is equivalent to + + function foo($object) { + if (!is_null($object) && !($object instanceof ClassName)) { + die('Argument 1 must be an instance of ClassName'); + } + } + . This syntax only applies to objects/classes, not built-in types. Index: Zend/zend_execute.c =================================================================== RCS file: /repository/ZendEngine2/zend_execute.c,v retrieving revision 1.449 diff -u -r1.449 zend_execute.c --- Zend/zend_execute.c 27 Mar 2003 17:57:47 -0000 1.449 +++ Zend/zend_execute.c 28 Mar 2003 17:09:54 -0000 @@ -4011,9 +4011,22 @@ { zval *arg = get_zval_ptr(&EX(opline)->op2, EX(Ts), &EG(free_op2), BP_VAR_R); zend_class_entry *ce = EX_T(EX(opline)->op1.u.var).EA.class_entry; + int allowed; + + switch (Z_TYPE_P(arg)) { + case IS_OBJECT: + allowed= instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC); + break; + + case IS_NULL: + allowed= (EX(opline)->op1.op_type == IS_VAR); + break; + + default: + allowed= 0; + } - if ((Z_TYPE_P(arg) != IS_OBJECT) - || !instanceof_function(Z_OBJCE_P(arg), ce TSRMLS_CC)) { + if (!allowed) { char *error_msg; if (ce->ce_flags & ZEND_ACC_INTERFACE) { @@ -4021,7 +4034,9 @@ } else { error_msg = "be an instance of"; } - zend_error(E_ERROR, "Argument %d must %s %s", EX(opline)->extended_value, error_msg, ce->name); + + zend_error(E_WARNING, "Argument %d must %s %s", EX(opline)->extended_value, error_msg, ce->name); + RETURN_FROM_EXECUTE_LOOP(execute_data); } NEXT_OPCODE(); Index: Zend/zend_language_parser.y =================================================================== RCS file: /repository/ZendEngine2/zend_language_parser.y,v retrieving revision 1.105 diff -u -r1.105 zend_language_parser.y --- Zend/zend_language_parser.y 26 Mar 2003 20:42:23 -0000 1.105 +++ Zend/zend_language_parser.y 28 Mar 2003 17:09:55 -0000 @@ -453,7 +453,8 @@ optional_class_type: /* empty */ { $$.op_type = IS_UNUSED; } - | fully_qualified_class_name { $$ = $1; } + | fully_qualified_class_name { $$ = $1; $$.op_type = IS_CONST; } + | '[' fully_qualified_class_name ']' { $$ = $2; $$.op_type = IS_VAR; } ; function_call_parameter_list: