mirror of
https://github.com/alrayyes/wiki.git
synced 2025-07-15 22:21:46 +00:00
Quartz sync: May 6, 2024, 10:40 PM
This commit is contained in:
parent
aee9145691
commit
4ef8371441
635 changed files with 22281 additions and 6 deletions
30
content/20201110103409-php_stringable_interface.md
Normal file
30
content/20201110103409-php_stringable_interface.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
---
|
||||
id: f97470da-6833-4ecf-81e2-40dd04f6c2a1
|
||||
title: PHP Stringable Interface
|
||||
---
|
||||
|
||||
# Description
|
||||
|
||||
Since [PHP 8.0](20201109133834-php_8_0), the stringable interface[^1] is
|
||||
automatically added to classes that implement the `__toString()` method
|
||||
|
||||
# Syntax
|
||||
|
||||
``` php
|
||||
class Foo
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return 'foo';
|
||||
}
|
||||
}
|
||||
|
||||
function bar(string|Stringable $stringable) { /* … */ }
|
||||
|
||||
bar(new Foo());
|
||||
bar('abc');
|
||||
```
|
||||
|
||||
# Footnotes
|
||||
|
||||
[^1]: <https://wiki.php.net/rfc/stringable>
|
Loading…
Add table
Add a link
Reference in a new issue