com php-src: more inheritance stuff: Zend/tests/type_declarat ions/typed_properties_008.phpt Zend/zend_inheri tance.c

From: Date: Mon, 07 Mar 2016 09:11:48 +0000
Subject: com php-src: more inheritance stuff: Zend/tests/type_declarat ions/typed_properties_008.phpt Zend/zend_inheri tance.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95627@lists.php.net to get a copy of this message
Commit: 3f56cd9f59532c77feb87c5446d58493ad71f499 Author: Joe Watkins <krakjoe@php.net> Mon, 7 Mar 2016 09:11:48 +0000 Parents: 64bce1e77c4e3daafddf001ef01b07c31147761f Branches: typed_ref_properties Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3f56cd9f59532c77feb87c5446d58493ad71f499 Log: more inheritance stuff Changed paths: A Zend/tests/type_declarations/typed_properties_008.phpt M Zend/zend_inheritance.c Diff: diff --git a/Zend/tests/type_declarations/typed_properties_008.phpt b/Zend/tests/type_declarations/typed_properties_008.phpt new file mode 100644 index 0000000..0efff90 --- /dev/null +++ b/Zend/tests/type_declarations/typed_properties_008.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test typed properties inheritance (missing info) +--FILE-- +<?php +class Foo { + public int $qux; +} + +class Bar extends Foo { + public $qux; +} +?> +--EXPECTF-- +Fatal error: Type of Bar::$qux must be integer (as in class Foo) in %s on line 8 + + diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index a405020..98ead9a 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -651,7 +651,6 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke if (UNEXPECTED(parent_info->type)) { /* TODO(krakjoe) comparing strings feels wrong */ - /* TODO(krakjoe) handle self, parent */ if (parent_info->type == IS_OBJECT) { if (child_info->type != IS_OBJECT || !zend_string_equals_ci(zend_resolve_property_type(parent_info), @@ -699,6 +698,24 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke } } } else { + if (UNEXPECTED(parent_info->type)) { + if (parent_info->type == IS_OBJECT) { + zend_error_noreturn(E_COMPILE_ERROR, + "Type of %s::$%s must be %s (as in class %s)", + ZSTR_VAL(ce->name), + ZSTR_VAL(key), + ZSTR_VAL(zend_resolve_property_type(parent_info)), + ZSTR_VAL(ce->parent->name)); + } else { + zend_error_noreturn(E_COMPILE_ERROR, + "Type of %s::$%s must be %s (as in class %s)", + ZSTR_VAL(ce->name), + ZSTR_VAL(key), + zend_get_type_by_const(parent_info->type), + ZSTR_VAL(ce->parent->name)); + } + } + if (UNEXPECTED(parent_info->flags & (ZEND_ACC_PRIVATE|ZEND_ACC_SHADOW))) { if (UNEXPECTED(ce->type & ZEND_INTERNAL_CLASS)) { child_info = zend_duplicate_property_info_internal(parent_info);

« previous php.cvs (#95627) next »