parent
33d35435ba
commit
f34fe1844d
10 changed files with 255 additions and 23 deletions
@ -0,0 +1,24 @@ |
||||
<?php |
||||
|
||||
trait FinalOverrideTrait |
||||
{ |
||||
public function execute(): void |
||||
{ |
||||
} |
||||
} |
||||
|
||||
class FinalMethodParent |
||||
{ |
||||
final public function execute(): void |
||||
{ |
||||
} |
||||
} |
||||
|
||||
class FinalMethodChild extends FinalMethodParent |
||||
{ |
||||
use FinalOverrideTrait; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
} |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
trait PrivateShadowTrait |
||||
{ |
||||
public function execute(string $value): string |
||||
{ |
||||
return $value; |
||||
} |
||||
} |
||||
|
||||
class PrivateMethodParent |
||||
{ |
||||
private function execute(int $value, bool $flag): int |
||||
{ |
||||
return $value; |
||||
} |
||||
} |
||||
|
||||
class PrivateMethodChild extends PrivateMethodParent |
||||
{ |
||||
use PrivateShadowTrait; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
var_dump((new PrivateMethodChild())->execute('ok')); |
||||
} |
||||
@ -0,0 +1,18 @@ |
||||
<?php |
||||
|
||||
trait MissingParentTrait |
||||
{ |
||||
public function execute(): void |
||||
{ |
||||
parent::execute(); |
||||
} |
||||
} |
||||
|
||||
class NoParentClass |
||||
{ |
||||
use MissingParentTrait; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
} |
||||
@ -0,0 +1,52 @@ |
||||
--TEST-- |
||||
Trait parent:: call remains bound to the composing class when inherited |
||||
--FILE-- |
||||
<?php |
||||
|
||||
trait ParentCallTrait |
||||
{ |
||||
public function source(): string |
||||
{ |
||||
return parent::source(); |
||||
} |
||||
} |
||||
|
||||
class RootClass |
||||
{ |
||||
public function source(): string |
||||
{ |
||||
return 'root'; |
||||
} |
||||
} |
||||
|
||||
class TraitUser extends RootClass |
||||
{ |
||||
use ParentCallTrait; |
||||
} |
||||
|
||||
class ChildClass extends TraitUser |
||||
{ |
||||
} |
||||
|
||||
class OtherRootClass |
||||
{ |
||||
public function source(): string |
||||
{ |
||||
return 'other'; |
||||
} |
||||
} |
||||
|
||||
class OtherTraitUser extends OtherRootClass |
||||
{ |
||||
use ParentCallTrait; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
var_dump((new ChildClass())->source()); |
||||
var_dump((new OtherTraitUser())->source()); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(4) "root" |
||||
string(5) "other" |
||||
@ -0,0 +1,36 @@ |
||||
--TEST-- |
||||
Trait parent:: call forwards an existing reference parameter |
||||
--FILE-- |
||||
<?php |
||||
|
||||
trait ParentReferenceTrait |
||||
{ |
||||
public function update(string &$value): void |
||||
{ |
||||
parent::update($value); |
||||
} |
||||
} |
||||
|
||||
class ReferenceParent |
||||
{ |
||||
public function update(string &$value): void |
||||
{ |
||||
$value = 'updated'; |
||||
} |
||||
} |
||||
|
||||
class ReferenceChild extends ReferenceParent |
||||
{ |
||||
use ParentReferenceTrait; |
||||
} |
||||
|
||||
function main(): void |
||||
{ |
||||
$value = 'initial'; |
||||
$child = new ReferenceChild(); |
||||
$child->update($value); |
||||
var_dump($value); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(7) "updated" |
||||
Loading…
Reference in new issue