Skip to content

Commit 8a9a858

Browse files
committed
Make implicit isset/unset inherit get/set modifiers
Closes issue php#39
1 parent 2199ff7 commit 8a9a858

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

Zend/tests/accessors/abstract_accessor_inherit_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class Bar extends Foo { }
1313

1414
?>
1515
--EXPECTF--
16-
Fatal error: Class Foo contains 1 abstract accessor and must be declared abstract or implement the remaining accessors (Foo::$foo->set) in %s on line %d
16+
Fatal error: Class Foo contains 2 abstract accessors and must be declared abstract or implement the remaining accessors (Foo::$foo->set, Foo::$foo->unset) in %s on line %d
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
Isset/unset inherit get/set visibility
3+
--FILE--
4+
<?php
5+
6+
abstract class Test {
7+
public $foo {
8+
protected get;
9+
private set;
10+
}
11+
public $bar {
12+
abstract get;
13+
final set;
14+
}
15+
}
16+
17+
echo new ReflectionProperty('Test', 'foo');
18+
echo new ReflectionProperty('Test', 'bar');
19+
20+
?>
21+
--EXPECTF--
22+
Accessor [ public $foo ] {
23+
Method [ <user> protected method $foo->get ] {
24+
@@ %s %d - %d
25+
}
26+
Method [ <user> private method $foo->set ] {
27+
@@ %s %d - %d
28+
29+
- Parameters [1] {
30+
Parameter #0 [ <required> $value ]
31+
}
32+
}
33+
Method [ <user> protected method $foo->isset ] {
34+
@@ %s %d - %d
35+
}
36+
Method [ <user> private method $foo->unset ] {
37+
@@ %s %d - %d
38+
}
39+
}
40+
]
41+
Accessor [ public $bar ] {
42+
Method [ <user> abstract public method $bar->get ] {
43+
@@ %s %d - %d
44+
}
45+
Method [ <user> final public method $bar->set ] {
46+
@@ %s %d - %d
47+
48+
- Parameters [1] {
49+
Parameter #0 [ <required> $value ]
50+
}
51+
}
52+
Method [ <user> abstract public method $bar->isset ] {
53+
@@ %s %d - %d
54+
}
55+
Method [ <user> final public method $bar->unset ] {
56+
@@ %s %d - %d
57+
}
58+
}
59+
]

Zend/zend_compile.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,13 +1767,19 @@ void zend_do_end_accessor_declaration(znode *function_token, const znode *body T
17671767
void zend_finalize_accessor(TSRMLS_D) { /* {{{ */
17681768
zend_property_info *property_info = CG(current_property_info);
17691769

1770+
zend_uint keep_flags = 0;
1771+
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) == 0) {
1772+
keep_flags = ZEND_ACC_PPP_MASK|ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT;
1773+
}
1774+
17701775
if (!property_info->accs[ZEND_ACCESSOR_ISSET] && property_info->accs[ZEND_ACCESSOR_GET]) {
17711776
znode zn_fntoken, zn_modifiers, zn_body;
17721777
INIT_ZNODE(zn_fntoken);
17731778
ZVAL_LONG(&zn_fntoken.u.constant, T_ISSET);
17741779

17751780
INIT_ZNODE(zn_modifiers);
1776-
Z_LVAL(zn_modifiers.u.constant) = 0;
1781+
Z_LVAL(zn_modifiers.u.constant)
1782+
= property_info->accs[ZEND_ACCESSOR_GET]->common.fn_flags & keep_flags;
17771783

17781784
INIT_ZNODE(zn_body);
17791785
Z_LVAL(zn_body.u.constant) = ZEND_ACC_ABSTRACT;
@@ -1787,7 +1793,8 @@ void zend_finalize_accessor(TSRMLS_D) { /* {{{ */
17871793
ZVAL_LONG(&zn_fntoken.u.constant, T_UNSET);
17881794

17891795
INIT_ZNODE(zn_modifiers);
1790-
Z_LVAL(zn_modifiers.u.constant) = 0;
1796+
Z_LVAL(zn_modifiers.u.constant)
1797+
= property_info->accs[ZEND_ACCESSOR_SET]->common.fn_flags & keep_flags;
17911798

17921799
INIT_ZNODE(zn_body);
17931800
Z_LVAL(zn_body.u.constant) = ZEND_ACC_ABSTRACT;

0 commit comments

Comments
 (0)