-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow access of backing value outside of hook
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
Zend/tests/property_hooks/backed_delegated_read_wirte.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
Attempted read/write of backing value in a delegated method throws | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
public $prop = 42 { | ||
get => $this->getProp($this->prop); | ||
set { | ||
$this->setProp($this->prop, $value); | ||
} | ||
} | ||
|
||
private function getProp($prop) { | ||
return $this->prop; | ||
} | ||
|
||
private function setProp($prop, $value) { | ||
$this->prop = $value; | ||
} | ||
|
||
public $prop2 = 42 { | ||
get => $this->prop2; | ||
set => $value; | ||
} | ||
} | ||
|
||
class Child extends Test { | ||
public $prop2 = 42 { | ||
get => parent::$prop2::get(); | ||
set { parent::$prop2::set($value); } | ||
} | ||
} | ||
|
||
$test = new Test; | ||
|
||
try { | ||
$test->prop = 0; | ||
} catch (Error $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
try { | ||
var_dump($test->prop); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
$child = new Child(); | ||
$child->prop2 = 43; | ||
var_dump($child->prop2); | ||
|
||
?> | ||
--EXPECT-- | ||
Must not write to property Test::$prop recursively | ||
Must not read from property Test::$prop recursively | ||
int(43) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters