Skip to content

Instantly share code, notes, and snippets.

@keopx
Last active August 29, 2015 14:05
Show Gist options
  • Save keopx/5c1f561ddaf2523d15f4 to your computer and use it in GitHub Desktop.
Save keopx/5c1f561ddaf2523d15f4 to your computer and use it in GitHub Desktop.
PHP Classes: when to use :: vs. ->
<?php
/**
* Simply put, :: is for class-level properties, and -> is for object-level properties.
* If the property belongs to the class, use ::
* If the property belongs to an instance of the class, use ->
*/
class Tester
{
public $foo;
const BLAH;
public static function bar(){}
}
$t = new Tester;
$t->foo;
Tester::bar();
Tester::BLAH;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment