note 124424 added to functions.arguments

From: Date: Fri, 22 Nov 2019 16:38:34 +0000
Subject: note 124424 added to functions.arguments
Groups: php.notes 
Request: Send a blank email to php-notes+get-213162@lists.php.net to get a copy of this message
You can use the class/interface as a type even if the class/interface is not defined yet or the class/interface implements current class/interface. <?php interface RouteInterface { public function getGroup(): ?RouteGroupInterface; } interface RouteGroupInterface extends RouteInterface { public function set(RouteInterface $item); } ?> 'self' type - alias to current class/interface, it's not changed in implementations. This code looks right but throw error: <?php class Route { protected $name; // method must return Route object public function setName(string $name): self { $this->name = $name; return $this; } } class RouteGroup extends Route { // method STILL must return only Route object public function setName(string $name): self { $name .= ' group'; return parent::setName($name); } } ?> ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.168 (proxied: 31.129.195.249) ---- Manual Page -- http://php.net/manual/en/functions.arguments.php Edit -- https://master.php.net/note/edit/124424 Del: integrated -- https://master.php.net/note/delete/124424/integrated Del: useless -- https://master.php.net/note/delete/124424/useless Del: bad code -- https://master.php.net/note/delete/124424/bad+code Del: spam -- https://master.php.net/note/delete/124424/spam Del: non-english -- https://master.php.net/note/delete/124424/non-english Del: in docs -- https://master.php.net/note/delete/124424/in+docs Del: other reasons-- https://master.php.net/note/delete/124424 Reject -- https://master.php.net/note/reject/124424 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#213162) next »