Created
February 13, 2017 03:02
-
-
Save farfromunique/5616722e22a97a6229cab243a4d3b624 to your computer and use it in GitHub Desktop.
a description of how PHP uses the -> operator
This file contains hidden or 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 | |
/* Here is some arbitrary code. Note that this is outside the Class definition */ | |
$var = 'Some value'; | |
function doStuff($param) { | |
echo 'Doing stuff with ' . $param . '!'; | |
} | |
/* Now, even though it's frowned upon, I'm going to include a class definition in the middle of my file */ | |
class Thing { | |
private $property; | |
public $differentProperty; | |
public function __construct($differentParam) { | |
/* This code fires automatically when a new Thing is created */ | |
$this->property = $differentParam; | |
/* Inside the Class definiton, so use $this. Note that $property becomees $this->property (only 1 $) */ | |
} | |
} | |
$thingamajig = new Thing($var); | |
/* Thing's $property is now 'Some value' */ | |
$thingamajig->differentPropery = 'Some other value'; | |
/* Thing's $differentProperty is now 'Some other value' */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment