note 125590 added to language.oop5.magic

From: Date: Thu, 10 Dec 2020 09:59:12 +0000
Subject: note 125590 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-215967@lists.php.net to get a copy of this message
Objects with __toString() passed within methods with type declarations(either from function arguments or return types) automagically converts it to string. <?php class Foo { public function __toString() { return 'foo'; } } class Bar { public function setAndGetFoo(string $foo) { return $foo; } public function getFoo(): string { return new Foo(); } } $foo = new Foo(); $bar = new Bar(); // string(3) "foo" var_dump($bar->setAndGetFoo($foo)); // string(3) "foo" var_dump($bar->getFoo()); ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.244 (proxied: 103.43.213.78) ---- Manual Page -- http://php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/125590 Del: integrated -- https://master.php.net/note/delete/125590/integrated Del: useless -- https://master.php.net/note/delete/125590/useless Del: bad code -- https://master.php.net/note/delete/125590/bad+code Del: spam -- https://master.php.net/note/delete/125590/spam Del: non-english -- https://master.php.net/note/delete/125590/non-english Del: in docs -- https://master.php.net/note/delete/125590/in+docs Del: other reasons-- https://master.php.net/note/delete/125590 Reject -- https://master.php.net/note/reject/125590 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215967) next »