Skip to content

Commit b04e5b0

Browse files
author
cpriest
committed
Changed zend_accessor_info to be a member of zend_property_info rather
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
1 parent 64699ee commit b04e5b0

16 files changed

+440
-493
lines changed

Zend/tests/accessors/accessor_isset_unset_auto_implement_basic.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ $o->b: 3600
3131
Getting $b
3232
is_null($o->b): 0
3333
Getting $b
34+
Getting $b
3435
isset($o->b): 1
3536
Unsetting $o->b
3637
Setting $b

Zend/tests/accessors/accessor_isset_unset_default_implemented_basic.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $o->b: 3600
2929
Getting $b
3030
is_null($o->b): 0
3131
Getting $b
32+
Getting $b
3233
isset($o->b): 1
3334
Unsetting $o->b
3435
Setting $b
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
--TEST--
2-
ZE2 Tests that an auto-implemented getter has a protected auto-implemented variable defined and that it can be retrieved through the accessor
2+
ZE2 Tests that an auto-implemented getter has an auto-implemented variable defined and that it can be retrieved through the accessor
33
--FILE--
44
<?php
55

66
class AccessorTest {
77
public $b {
88
get;
99
}
10-
11-
public function __construct() {
12-
$this->__b = 5;
13-
}
1410
}
1511

1612
$o = new AccessorTest();
1713

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

2416
echo "\$o->b: ".$o->b."\n";
2517
echo "Done\n";
2618
?>
2719
--EXPECTF--
28-
Protected property: $__b exists.
29-
$o->b: 5
30-
Done
20+
object(AccessorTest)#1 (1) {
21+
["b"]=>
22+
NULL
23+
}
24+
$o->b:
25+
Done

Zend/tests/accessors/accessor_object_get_undefined_error.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ echo "\$o->b: ".$o->b."\n";
1515
echo "Done\n";
1616
?>
1717
--EXPECTF--
18-
Fatal error: Cannot get property AccessorTest::$b, no getter defined. in %s on line %d
18+
Warning: Cannot get property AccessorTest::$b, no getter defined in %s on line %d
19+
$o->b:
20+
Done
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
ZE2 Tests that an auto-implemented setter has a protected auto-implemented variable defined and that it can be changed through the accessor
2+
ZE2 Tests that an auto-implemented setter has an auto-implemented variable defined and that it can be changed through the accessor
33
--FILE--
44
<?php
55

@@ -9,26 +9,24 @@ class AccessorTest {
99
}
1010

1111
public function __construct() {
12-
$this->__b = 5;
12+
$this->b = 5;
1313
}
14-
public function _getProtectedValue() { return $this->__b; }
1514
}
1615

1716
$o = new AccessorTest();
1817

19-
$rf = new ReflectionClass($o);
20-
foreach($rf->getProperties(ReflectionProperty::IS_PROTECTED) as $rfp) {
21-
if($rfp->getName() == '__b')
22-
echo "Protected property: \$".$rfp->getName()." exists.\n";
23-
}
24-
25-
echo "\$o->b: ".$o->_getProtectedValue()."\n";
18+
print_r($o);
2619
$o->b = 10;
27-
echo "\$o->b: ".$o->_getProtectedValue()."\n";
20+
print_r($o);
2821
echo "Done\n";
2922
?>
3023
--EXPECTF--
31-
Protected property: $__b exists.
32-
$o->b: 5
33-
$o->b: 10
24+
AccessorTest Object
25+
(
26+
[b] => 5
27+
)
28+
AccessorTest Object
29+
(
30+
[b] => 10
31+
)
3432
Done

Zend/tests/accessors/accessor_object_set_undefined_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ $o = new AccessorTest();
1313
$o->b = 10;
1414
?>
1515
--EXPECTF--
16-
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
16+
Warning: Cannot set property AccessorTest::$b, no setter defined in %s on line %d

Zend/tests/accessors/accessor_object_set_undefined_unset_called_error.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ $o = new AccessorTest();
1414
unset($o->b);
1515
?>
1616
--EXPECTF--
17-
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
17+
Fatal error: Cannot set property AccessorTest::$b, no setter defined. in %s on line %d
18+
19+
This test needs to be re-worked / checked against v1.2 changes. Technically it is working as it should
20+
(unset is not causing an error) but that "feature" has not yet been put in place.
21+
Need to trace what's going on here.

Zend/tests/accessors/accessor_std_lazy_load_with_getter_basic.phpt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ class TimePeriod {
1111
public $Hours {
1212
get {
1313
echo "Get Hours Called\n";
14-
return $this->Hours = 1; /* Calls Setter */
14+
return $this->Hours ?: $this->Hours = 2; /* Calls Setter */
1515
}
1616
set {
17-
$this->Hours = 1; /* Sets an anonymous property due to guard allowing lazy load */
17+
echo "Set Hours Called ({$value})\n";
18+
$this->Hours = $value;
1819
}
1920
}
2021
}
@@ -24,8 +25,16 @@ $o = new TimePeriod();
2425
echo $o->Hours."\n";
2526
echo $o->Hours."\n";
2627
$o->Hours = 4;
28+
echo $o->Hours."\n";
29+
echo "Done\n";
2730
?>
2831
--EXPECTF--
2932
Get Hours Called
30-
1
31-
1
33+
Set Hours Called (2)
34+
2
35+
Get Hours Called
36+
2
37+
Set Hours Called (4)
38+
Get Hours Called
39+
4
40+
Done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
ZE2 Tests that an accessor cannot be declared if a property is already declared
3+
--FILE--
4+
<?php
5+
6+
class TimePeriod {
7+
public $Seconds;
8+
public $Seconds {
9+
}
10+
}
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Cannot redeclare TimePeriod::$Seconds in %s on line %d

Zend/zend.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ struct _zend_class_entry {
480480

481481
HashTable function_table;
482482
HashTable properties_info;
483-
HashTable accessors;
484483

485484
zval **default_properties_table;
486485
zval **default_static_members_table;

Zend/zend_API.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,6 +3402,7 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, const char *name, in
34023402
property_info.doc_comment_len = doc_comment_len;
34033403

34043404
property_info.ce = ce;
3405+
property_info.ai = NULL;
34053406

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

0 commit comments

Comments
 (0)