{"id":5124,"date":"2016-10-18T16:05:33","date_gmt":"2016-10-18T20:05:33","guid":{"rendered":"http:\/\/www.dr-chuck.com\/csev-blog\/?p=5124"},"modified":"2016-10-18T16:06:22","modified_gmt":"2016-10-18T20:06:22","slug":"what-is-static-double-colon-this-and-arrow-in-php-oo","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2016\/10\/what-is-static-double-colon-this-and-arrow-in-php-oo\/","title":{"rendered":"What is static, double colon (::), $this, and arrow(->) in PHP OO"},"content":{"rendered":"<p>I wrote this code to answer some PHP Object Oriented questions during office hours.<\/p>\n<pre>\r\nfunction plus($x, $y) {\r\n    return $x + $y;\r\n}\r\n\r\nclass Thing {\r\n    public $value;\r\n    private $a;\r\n    protected $b;\r\n\r\n    function __construct($start=0) {\r\n        echo(\"Construct\\n\");\r\n        var_dump($this-&gt;value);\r\n        $this-&gt;value = $start;\r\n        $value = 12345;\r\n        var_dump($this-&gt;value);\r\n        echo(\"Done\\n\");\r\n    }\r\n\r\n    public static function add($x, $y) {\r\n        \/\/ Cannot use $this\r\n        echo(\"Adding $x $y \\n\");\r\n        return $x + $y;\r\n    }\r\n\r\n    public function increment($x) {\r\n        $this-&gt;value += $x;\r\n        echo(\"New:\" . $this-&gt;value . \"\\n\");\r\n    }\r\n\r\n    public function inc2($x, $y) {\r\n        $this-&gt;increment($x);\r\n        $this-&gt;increment($y);\r\n    }\r\n\r\n    public function add10() {\r\n        $this-&gt;value = self::add($this-&gt;value, 10);\r\n        $this-&gt;value = $this-&gt;add($this-&gt;value, 10);\r\n        $this-&gt;inc2();\r\n    }\r\n\r\n    function __destruct() {\r\n        echo(\"AAAAAAAAAAAAAARGH!!\\n\");\r\n    }\r\n\r\n}\r\n\r\n$y = plus(3,4);\r\n\r\n$y = Thing::add(3,4);\r\n\r\n$z = new Thing(7);\r\n$a = new Thing(10);\r\n\r\n$z-&gt;increment(4);\r\n\r\n$a-&gt;increment(5);\r\n\r\n$y = $z-&gt;add(5,6);\r\n\r\nunset($z);\r\necho(\"The last line\\n\");\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I wrote this code to answer some PHP Object Oriented questions during office hours. function plus($x, $y) { return $x + $y; } class Thing { public $value; private $a; protected $b; function __construct($start=0) { echo(&#8220;Construct\\n&#8221;); var_dump($this-&gt;value); $this-&gt;value = $start; $value = 12345; var_dump($this-&gt;value); echo(&#8220;Done\\n&#8221;); } public static function add($x, $y) { \/\/ Cannot use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5124","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/5124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=5124"}],"version-history":[{"count":5,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/5124\/revisions"}],"predecessor-version":[{"id":5129,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/5124\/revisions\/5129"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=5124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=5124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=5124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}