Fixed type-hint compatibility check in namespaces

This commit is contained in:
Dmitry Stogov 2007-11-09 13:34:39 +00:00
parent 98b3c247a8
commit 8646d9afce
2 changed files with 43 additions and 1 deletions

31
Zend/tests/ns_056.phpt Executable file
View File

@ -0,0 +1,31 @@
--TEST--
056: type-hint compatibility in namespaces
--SKIPIF--
<?php if (!extension_loaded("spl")) die("skip SPL is no available"); ?>
--FILE--
<?php
namespace test::ns1;
class Foo implements SplObserver {
function update(SplSubject $x) {
echo "ok\n";
}
}
class Bar implements SplSubject {
function attach(SplObserver $x) {
echo "ok\n";
}
function notify() {
}
function detach(SplObserver $x) {
}
}
$foo = new Foo();
$bar = new Bar();
$bar->attach($foo);
$foo->update($bar);
?>
--EXPECT--
ok
ok

View File

@ -2176,7 +2176,18 @@ static zend_bool zend_do_perform_implementation_check(zend_function *fe, zend_fu
}
if (fe->common.arg_info[i].class_name
&& strcmp(fe->common.arg_info[i].class_name, proto->common.arg_info[i].class_name)!=0) {
return 0;
char *colon;
if (fe->common.type == ZEND_USER_FUNCTION &&
strchr(proto->common.arg_info[i].class_name, ':') == NULL &&
(colon = zend_memrchr(fe->common.arg_info[i].class_name, ':', fe->common.arg_info[i].class_name_len)) != NULL &&
strcmp(colon+1, proto->common.arg_info[i].class_name) == 0) {
efree((char*)fe->common.arg_info[i].class_name);
fe->common.arg_info[i].class_name = estrndup(proto->common.arg_info[i].class_name, proto->common.arg_info[i].class_name_len);
fe->common.arg_info[i].class_name_len = proto->common.arg_info[i].class_name_len;
} else {
return 0;
}
}
if (fe->common.arg_info[i].array_type_hint != proto->common.arg_info[i].array_type_hint) {
/* Only one has an array type hint and the other one doesn't */