Skip to content

Commit

Permalink
Changed zend_accessor_info to be a member of zend_property_info rather
Browse files Browse the repository at this point in the history
than it's own set of hash pairs.  This greatly simplified things and
eliminated a hash lookup for every property access.  Also reduced memory
footprint as a separate copy of doc_comments did not need to be
maintained.

Fixed php#11
  • Loading branch information
cpriest committed Jan 2, 2013
1 parent 64699ee commit b04e5b0
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ $o->b: 3600
Getting $b
is_null($o->b): 0
Getting $b
Getting $b
isset($o->b): 1
Unsetting $o->b
Setting $b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $o->b: 3600
Getting $b
is_null($o->b): 0
Getting $b
Getting $b
isset($o->b): 1
Unsetting $o->b
Setting $b
Expand Down
21 changes: 8 additions & 13 deletions Zend/tests/accessors/accessor_object_get_autoimplement_basic.phpt
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
--TEST--
ZE2 Tests that an auto-implemented getter has a protected auto-implemented variable defined and that it can be retrieved through the accessor
ZE2 Tests that an auto-implemented getter has an auto-implemented variable defined and that it can be retrieved through the accessor
--FILE--
<?php

class AccessorTest {
public $b {
get;
}

public function __construct() {
$this->__b = 5;
}
}

$o = new AccessorTest();

$rf = new ReflectionClass($o);
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
if($rfp->getName() == '__b')
echo "Protected property: \$".$rfp->getName()." exists.\n";
}
var_dump($o);

echo "\$o->b: ".$o->b."\n";
echo "Done\n";
?>
--EXPECTF--
Protected property: $__b exists.
$o->b: 5
Done
object(AccessorTest)#1 (1) {
["b"]=>
NULL
}
$o->b:
Done
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ echo "\$o->b: ".$o->b."\n";
echo "Done\n";
?>
--EXPECTF--
Fatal error: Cannot get property AccessorTest::$b, no getter defined. in %s on line %d
Warning: Cannot get property AccessorTest::$b, no getter defined in %s on line %d
$o->b:
Done
26 changes: 12 additions & 14 deletions Zend/tests/accessors/accessor_object_set_autoimplement_basic.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
ZE2 Tests that an auto-implemented setter has a protected auto-implemented variable defined and that it can be changed through the accessor
ZE2 Tests that an auto-implemented setter has an auto-implemented variable defined and that it can be changed through the accessor
--FILE--
<?php

Expand All @@ -9,26 +9,24 @@ class AccessorTest {
}

public function __construct() {
$this->__b = 5;
$this->b = 5;
}
public function _getProtectedValue() { return $this->__b; }
}

$o = new AccessorTest();

$rf = new ReflectionClass($o);
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
if($rfp->getName() == '__b')
echo "Protected property: \$".$rfp->getName()." exists.\n";
}

echo "\$o->b: ".$o->_getProtectedValue()."\n";
print_r($o);
$o->b = 10;
echo "\$o->b: ".$o->_getProtectedValue()."\n";
print_r($o);
echo "Done\n";
?>
--EXPECTF--
Protected property: $__b exists.
$o->b: 5
$o->b: 10
AccessorTest Object
(
[b] => 5
)
AccessorTest Object
(
[b] => 10
)
Done
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ $o = new AccessorTest();
$o->b = 10;
?>
--EXPECTF--
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
Warning: Cannot set property AccessorTest::$b, no setter defined in %s on line %d
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ $o = new AccessorTest();
unset($o->b);
?>
--EXPECTF--
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d

This test needs to be re-worked / checked against v1.2 changes. Technically it is working as it should
(unset is not causing an error) but that "feature" has not yet been put in place.
Need to trace what's going on here.
17 changes: 13 additions & 4 deletions Zend/tests/accessors/accessor_std_lazy_load_with_getter_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ class TimePeriod {
public $Hours {
get {
echo "Get Hours Called\n";
return $this->Hours = 1; /* Calls Setter */
return $this->Hours ?: $this->Hours = 2; /* Calls Setter */
}
set {
$this->Hours = 1; /* Sets an anonymous property due to guard allowing lazy load */
echo "Set Hours Called ({$value})\n";
$this->Hours = $value;
}
}
}
Expand All @@ -24,8 +25,16 @@ $o = new TimePeriod();
echo $o->Hours."\n";
echo $o->Hours."\n";
$o->Hours = 4;
echo $o->Hours."\n";
echo "Done\n";
?>
--EXPECTF--
Get Hours Called
1
1
Set Hours Called (2)
2
Get Hours Called
2
Set Hours Called (4)
Get Hours Called
4
Done
14 changes: 14 additions & 0 deletions Zend/tests/accessors/duplicate_property_declared_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
ZE2 Tests that an accessor cannot be declared if a property is already declared
--FILE--
<?php

class TimePeriod {
public $Seconds;
public $Seconds {
}
}

?>
--EXPECTF--
Fatal error: Cannot redeclare TimePeriod::$Seconds in %s on line %d
1 change: 0 additions & 1 deletion Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ struct _zend_class_entry {

HashTable function_table;
HashTable properties_info;
HashTable accessors;

zval **default_properties_table;
zval **default_static_members_table;
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3402,6 +3402,7 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, in
property_info.doc_comment_len = doc_comment_len;

property_info.ce = ce;
property_info.ai = NULL;

zend_hash_quick_update(&ce->properties_info, name, name_length+1, h, &property_info, sizeof(zend_property_info), NULL);

Expand Down
Loading

0 comments on commit b04e5b0

Please sign in to comment.