Navigation Menu

Skip to content

Commit

Permalink
Make implicit isset/unset inherit get/set modifiers
Browse files Browse the repository at this point in the history
Closes issue php#39
  • Loading branch information
nikic committed Jan 14, 2013
1 parent 2199ff7 commit 8a9a858
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Zend/tests/accessors/abstract_accessor_inherit_error.phpt
Expand Up @@ -13,4 +13,4 @@ class Bar extends Foo { }

?>
--EXPECTF--
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
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
59 changes: 59 additions & 0 deletions Zend/tests/accessors/isset_unset_inherit_get_set_modifiers.phpt
@@ -0,0 +1,59 @@
--TEST--
Isset/unset inherit get/set visibility
--FILE--
<?php

abstract class Test {
public $foo {
protected get;
private set;
}
public $bar {
abstract get;
final set;
}
}

echo new ReflectionProperty('Test', 'foo');
echo new ReflectionProperty('Test', 'bar');

?>
--EXPECTF--
Accessor [ public $foo ] {
Method [ <user> protected method $foo->get ] {
@@ %s %d - %d
}
Method [ <user> private method $foo->set ] {
@@ %s %d - %d

- Parameters [1] {
Parameter #0 [ <required> $value ]
}
}
Method [ <user> protected method $foo->isset ] {
@@ %s %d - %d
}
Method [ <user> private method $foo->unset ] {
@@ %s %d - %d
}
}
]
Accessor [ public $bar ] {
Method [ <user> abstract public method $bar->get ] {
@@ %s %d - %d
}
Method [ <user> final public method $bar->set ] {
@@ %s %d - %d

- Parameters [1] {
Parameter #0 [ <required> $value ]
}
}
Method [ <user> abstract public method $bar->isset ] {
@@ %s %d - %d
}
Method [ <user> final public method $bar->unset ] {
@@ %s %d - %d
}
}
]
11 changes: 9 additions & 2 deletions Zend/zend_compile.c
Expand Up @@ -1767,13 +1767,19 @@ void zend_do_end_accessor_declaration(znode *function_token, const znode *body T
void zend_finalize_accessor(TSRMLS_D) { /* {{{ */
zend_property_info *property_info = CG(current_property_info);

zend_uint keep_flags = 0;
if ((CG(active_class_entry)->ce_flags & ZEND_ACC_INTERFACE) == 0) {
keep_flags = ZEND_ACC_PPP_MASK|ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT;
}

if (!property_info->accs[ZEND_ACCESSOR_ISSET] && property_info->accs[ZEND_ACCESSOR_GET]) {
znode zn_fntoken, zn_modifiers, zn_body;
INIT_ZNODE(zn_fntoken);
ZVAL_LONG(&zn_fntoken.u.constant, T_ISSET);

INIT_ZNODE(zn_modifiers);
Z_LVAL(zn_modifiers.u.constant) = 0;
Z_LVAL(zn_modifiers.u.constant)
= property_info->accs[ZEND_ACCESSOR_GET]->common.fn_flags & keep_flags;

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

INIT_ZNODE(zn_modifiers);
Z_LVAL(zn_modifiers.u.constant) = 0;
Z_LVAL(zn_modifiers.u.constant)
= property_info->accs[ZEND_ACCESSOR_SET]->common.fn_flags & keep_flags;

INIT_ZNODE(zn_body);
Z_LVAL(zn_body.u.constant) = ZEND_ACC_ABSTRACT;
Expand Down

0 comments on commit 8a9a858

Please sign in to comment.