3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base { private $basePrivate = 'private in base class'; protected $baseProtected = 'protected in base class'; public $basePublic = 'public in base class'; public function baseExample() { // We *can't* access $this->doesNotExist because it doesn't exist. echo $this->doesNotExist; // We *can* access the following: echo __LINE__ . ': ' . $this->basePrivate . "\n"; echo __LINE__ . ': ' . $this->baseProtected . "\n"; echo __LINE__ . ': ' . $this->basePublic . "\n"; } } class Child extends Base { private $childPrivate = 'private in child class'; protected $childProtected = 'protected in child class'; public $childPubilc = 'public in child class'; public function childExample() { // We can't access $this->basePrivate because the base class // declared it as private (this is the what private means) echo $this->basePrivate; // We can't access $this->doesNotExist because it doesn't exist. echo $this->doesNotExist; // We *can* access the following: echo __LINE__ . ': ' . $this->baseProtected . "\n"; echo __LINE__ . ': ' . $this->basePublic . "\n"; echo __LINE__ . ': ' . $this->childPrivate . "\n"; echo __LINE__ . ': ' . $this->childProtected . "\n"; echo __LINE__ . ': ' . $this->childPublic . "\n"; } } // Now we'll create instances of these classes. Since we're now outside of the // classes (i.e. we're using instances of the classes and not in the actual code of the class) // we can now only access public properties. $base = new Base; $child = new Child; // Let's run our demo methods to see the results echo $base->baseExample(); echo $child->childExample(); // Outside the class, we *can't* access the following: echo $base->doesNotExist; echo $base->basePrivate; echo $base->baseProtected; echo $child->doesNotExist; echo $child->basePrivate; echo $child->baseProtected; echo $child->childPrivate; echo $child->childProtected; // Outside the class, we *can* access public properties echo __LINE__ . ': ' . $base->basePublic . "\n"; echo __LINE__ . ': ' . $child->basePublic . "\n"; echo __LINE__ . ': ' . $child->childPublic . "\n";
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined property: Base::$doesNotExist in /in/IhXsh on line 12 15: private in base class 16: protected in base class 17: public in base class Warning: Undefined property: Child::$basePrivate in /in/IhXsh on line 31 Warning: Undefined property: Child::$doesNotExist in /in/IhXsh on line 34 37: protected in base class 38: public in base class 39: private in child class 40: protected in child class Warning: Undefined property: Child::$childPublic in /in/IhXsh on line 41 41: Warning: Undefined property: Base::$doesNotExist in /in/IhXsh on line 56 Fatal error: Uncaught Error: Cannot access private property Base::$basePrivate in /in/IhXsh:57 Stack trace: #0 {main} thrown in /in/IhXsh on line 57
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
70.36 ms | 402 KiB | 8 Q