Created
November 1, 2020 23:13
-
-
Save guibranco/c63d592e8e0bfd579bd7c55a4da43555 to your computer and use it in GitHub Desktop.
Herança em PHP - PHP Brasil - Facebook - https://www.facebook.com/groups/142151625841770/permalink/3555488671174698/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class A { | |
private $x; | |
public function __construct(){ | |
$this->x = "testando"; | |
} | |
public function __toString(){ | |
return "A::" . $this->x . "<br />\r\n"; | |
} | |
} | |
class B extends A { | |
public function __toString(){ | |
echo "B::".$this->x."<br />\r\n"; | |
return "Parent::". parent::__toString(); | |
} | |
} | |
$b = new B(); | |
$b->x = "private field do A não é usado, cria-se um dinamicamente em B"; | |
echo $b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment