Skip to content

Instantly share code, notes, and snippets.

@guibranco
Created November 1, 2020 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guibranco/c63d592e8e0bfd579bd7c55a4da43555 to your computer and use it in GitHub Desktop.
Save guibranco/c63d592e8e0bfd579bd7c55a4da43555 to your computer and use it in GitHub Desktop.
<?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