note 129120 added to class.stringable

From: Date: Sat, 23 Dec 2023 06:53:32 +0000
Subject: note 129120 added to class.stringable
Groups: php.notes 
Request: Send a blank email to php-notes+get-221074@lists.php.net to get a copy of this message
Most methods that consume strings will have an empty value for a stringable. Despite empty() always saying a stringable is not empty. <?php class Uuid implements Stringable { private string $value; public function __construct(string $value) { $this->value = $value; } public function __toString(): string { return $this->value; } } $x = new Uuid('asdf'); var_dump(['b'=>$x]); /* array(1) { ["b"]=> object(Uuid)#1 (1) { ["value":"Uuid":private]=> string(4) "asdf" } } */ var_dump(['a'=>$x]); // "{"a":{}}" ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 177.50.225.251) ---- Manual Page -- https://php.net/manual/en/class.stringable.php Edit -- https://main.php.net/note/edit/129120 Del: integrated -- https://main.php.net/note/delete/129120/integrated Del: useless -- https://main.php.net/note/delete/129120/useless Del: bad code -- https://main.php.net/note/delete/129120/bad+code Del: spam -- https://main.php.net/note/delete/129120/spam Del: non-english -- https://main.php.net/note/delete/129120/non-english Del: in docs -- https://main.php.net/note/delete/129120/in+docs Del: other reasons-- https://main.php.net/note/delete/129120 Reject -- https://main.php.net/note/reject/129120 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221074) next »