Skip to content

Instantly share code, notes, and snippets.

@farfromunique
Created February 13, 2017 03:02
Show Gist options
  • Save farfromunique/5616722e22a97a6229cab243a4d3b624 to your computer and use it in GitHub Desktop.
Save farfromunique/5616722e22a97a6229cab243a4d3b624 to your computer and use it in GitHub Desktop.
a description of how PHP uses the -> operator
<?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