[PHP] PHP8 Stringable 미리 알아보기


[PHP] PHP8 Stringable 미리 알아보기

Stringable란? # "Stringable" 인터페이스는 "__toString()"을 구현하는 모든 힌트를 입력하는 데 사용할 수 있다. 클래스가 "__toString()"을 구현할 때마다 자동으로 뒤에서 인터페이스를 구현하므로 수동으로 구현할 필요가 없다. class Foo implements Stringable { public function __toString(): string { return 'foo'; } } $foo = new Foo(); echo $foo; // -> foo 예제 https://pronist.tistory.com/60 class MyClass implements Stringable { public function __toString(): string { return 'Hello, world'; } } echo new MyClass(); // -> Hello, world 참고 링크 PHP: rfc:stringable PHP RFC: Add String...


#php #php8 #Stringable

원문링크 : [PHP] PHP8 Stringable 미리 알아보기