note 123338 added to functions.arguments
| From: | dmitry dot balabka at gmail dot com | Date: | Tue, 13 Nov 2018 09:47:01 +0000 |
| Subject: | note 123338 added to functions.arguments | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209687@lists.php.net to get a copy of this message | ||
There is a possibility to use parent keyword as type hint which is not mentioned in the
documentation.
Following code snippet will be executed w/o errors on PHP version 7. In this example, parent keyword
is referencing on ParentClass instead of ClassTrait.
<?php
namespace TestTypeHints;
class ParentClass
{
public function someMethod()
{
echo 'Some method called' . \PHP_EOL;
}
}
trait ClassTrait
{
private $original;
public function __construct(parent $original)
{
$this->original = $original;
}
protected function getOriginal(): parent
{
return $this->original;
}
}
class Implementation extends ParentClass
{
use ClassTrait;
public function callSomeMethod()
{
$this->getOriginal()->someMethod();
}
}
$obj = new Implementation(new ParentClass());
$obj->callSomeMethod();
?>
Outputs:
Some method called
----
Server IP: 208.43.231.9
Probable Submitter: 91.221.62.80
----
Manual Page -- http://php.net/manual/en/functions.arguments.php
Edit -- https://master.php.net/note/edit/123338
Del: integrated -- https://master.php.net/note/delete/123338/integrated
Del: useless -- https://master.php.net/note/delete/123338/useless
Del: bad code -- https://master.php.net/note/delete/123338/bad+code
Del: spam -- https://master.php.net/note/delete/123338/spam
Del: non-english -- https://master.php.net/note/delete/123338/non-english
Del: in docs -- https://master.php.net/note/delete/123338/in+docs
Del: other reasons-- https://master.php.net/note/delete/123338
Reject -- https://master.php.net/note/reject/123338
Search -- https://master.php.net/manage/user-notes.php