-
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.
If __toString() comes from a trait, implement Stringable during inheritance.
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Bug #81582: Stringable not implicitly declared if __toString() came from a trait | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
public function __toString(): string { | ||
return "ok"; | ||
} | ||
} | ||
|
||
class C { | ||
use T; | ||
} | ||
|
||
var_dump(new C instanceof Stringable); | ||
|
||
?> | ||
--EXPECT-- | ||
bool(true) |
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,20 @@ | ||
--TEST-- | ||
__toString() from trait with invalid return type | ||
--FILE-- | ||
<?php | ||
|
||
trait T { | ||
public function __toString(): int { | ||
return "ok"; | ||
} | ||
} | ||
|
||
class C { | ||
use T; | ||
} | ||
|
||
var_dump(new C instanceof Stringable); | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Declaration of T::__toString(): int must be compatible with Stringable::__toString(): string 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
typo: important → imported