Skip to content

Instantly share code, notes, and snippets.

@matmar10
Created October 5, 2021 14:29
Show Gist options
  • Save matmar10/4e5627958f9d4eda23a6a0f2e8b89494 to your computer and use it in GitHub Desktop.
Save matmar10/4e5627958f9d4eda23a6a0f2e8b89494 to your computer and use it in GitHub Desktop.
Test run-time set of property specified in child class
<?php
class ChildClass extends ParentClass {
protected $json;
public function __construct() {
parent::__construct();
}
public function toString() {
return json_encode($this->json);
}
}
<?php
require_once('ParentClass.php');
require_once('ChildClass.php');
$obj = new ChildClass();
echo $obj->toString();
<?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