Created
October 5, 2021 14:29
-
-
Save matmar10/4e5627958f9d4eda23a6a0f2e8b89494 to your computer and use it in GitHub Desktop.
Test run-time set of property specified in child class
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 ChildClass extends ParentClass { | |
protected $json; | |
public function __construct() { | |
parent::__construct(); | |
} | |
public function toString() { | |
return json_encode($this->json); | |
} | |
} |
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 | |
require_once('ParentClass.php'); | |
require_once('ChildClass.php'); | |
$obj = new ChildClass(); | |
echo $obj->toString(); |
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 ParentClass { | |
public function __construct() { | |
// json is specified as a member but int he child class | |
// will this cause an issue? | |
$this->json = array("foo" => "bar"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment