-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: https://wiki.php.net/rfc/property-hooks Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
- Loading branch information
Showing
240 changed files
with
9,470 additions
and
1,050 deletions.
There are no files selected for viewing
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
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
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
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
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
Abstract hooks compile successfully | ||
--FILE-- | ||
<?php | ||
|
||
abstract class A { | ||
public abstract $prop { | ||
get; | ||
set {} | ||
} | ||
} | ||
|
||
class B extends A { | ||
public $prop { | ||
get {} | ||
} | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
15 changes: 15 additions & 0 deletions
15
Zend/tests/property_hooks/abstract_hook_in_non_abstract_class.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,15 @@ | ||
--TEST-- | ||
Abstract hooks in non-abstract class gives an error | ||
--FILE-- | ||
<?php | ||
|
||
class Test { | ||
public abstract $prop { | ||
get; | ||
set {} | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class Test contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Test::$prop::get) in %s on line %d |
17 changes: 17 additions & 0 deletions
17
Zend/tests/property_hooks/abstract_hook_not_implemented.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,17 @@ | ||
--TEST-- | ||
Abstract hooks that are not implemented throw an error | ||
--FILE-- | ||
<?php | ||
|
||
abstract class A { | ||
public abstract $prop { | ||
get; | ||
set {} | ||
} | ||
} | ||
|
||
class B extends A {} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class B contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (A::$prop::get) in %s on line %d |
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,17 @@ | ||
--TEST-- | ||
Explicit hooked property satisfies abstract property | ||
--FILE-- | ||
<?php | ||
|
||
abstract class A { | ||
abstract public $prop { get; set; } | ||
} | ||
|
||
class B extends A { | ||
public $prop { get {} set {} } | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
14 changes: 14 additions & 0 deletions
14
Zend/tests/property_hooks/abstract_prop_not_implemented.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,14 @@ | ||
--TEST-- | ||
Abstract property not implemented throws an error | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
abstract public $prop { get; set; } | ||
} | ||
|
||
class B extends A {} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Class A contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (A::$prop::get, A::$prop::set) in %s on line %d |
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,17 @@ | ||
--TEST-- | ||
Plain property satisfies abstract property | ||
--FILE-- | ||
<?php | ||
|
||
abstract class A { | ||
abstract public $prop { get; set; } | ||
} | ||
|
||
class B extends A { | ||
public $prop; | ||
} | ||
|
||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
===DONE=== |
12 changes: 12 additions & 0 deletions
12
Zend/tests/property_hooks/abstract_prop_without_hooks.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,12 @@ | ||
--TEST-- | ||
Abstract property without hook is illegal | ||
--FILE-- | ||
<?php | ||
|
||
class C { | ||
abstract public $prop; | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Only hooked properties may be declared abstract in %s on line %d |
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,49 @@ | ||
--TEST-- | ||
Array offset on ArrayAccess object in virtual property is allowed | ||
--FILE-- | ||
<?php | ||
|
||
class Collection implements ArrayAccess { | ||
public function offsetExists(mixed $offset): bool { | ||
echo __METHOD__ . "\n"; | ||
return true; | ||
} | ||
|
||
public function offsetGet(mixed $offset): mixed { | ||
echo __METHOD__ . "\n"; | ||
return true; | ||
} | ||
|
||
public function offsetSet(mixed $offset, mixed $value): void { | ||
echo __METHOD__ . "\n"; | ||
} | ||
|
||
public function offsetUnset(mixed $offset): void { | ||
echo __METHOD__ . "\n"; | ||
} | ||
} | ||
|
||
class C { | ||
public function __construct( | ||
public Collection $collection = new Collection(), | ||
) {} | ||
public $prop { | ||
get => $this->collection; | ||
} | ||
} | ||
|
||
$c = new C(); | ||
var_dump($c->prop['foo']); | ||
var_dump($c->prop[] = 'foo'); | ||
var_dump(isset($c->prop['foo'])); | ||
unset($c->prop['foo']); | ||
|
||
?> | ||
--EXPECT-- | ||
Collection::offsetGet | ||
bool(true) | ||
Collection::offsetSet | ||
string(3) "foo" | ||
Collection::offsetExists | ||
bool(true) | ||
Collection::offsetUnset |
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,45 @@ | ||
--TEST-- | ||
Hook AST printing | ||
--FILE-- | ||
<?php | ||
|
||
try { | ||
assert(false && new class { | ||
public $prop1 { get; set; } | ||
public $prop2 { | ||
get { | ||
return parent::$prop1::get(); | ||
} | ||
final set { | ||
echo 'Foo'; | ||
$this->prop1 = 42; | ||
} | ||
} | ||
public $prop3 = 1 { | ||
get => 42; | ||
} | ||
}); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
assert(false && new class { | ||
public $prop1 { | ||
get; | ||
set; | ||
} | ||
public $prop2 { | ||
get { | ||
return parent::$prop1::get(); | ||
} | ||
final set { | ||
echo 'Foo'; | ||
$this->prop1 = 42; | ||
} | ||
} | ||
public $prop3 = 1 { | ||
get => 42; | ||
} | ||
}) |
Oops, something went wrong.