Last active
August 29, 2015 14:05
-
-
Save keopx/5c1f561ddaf2523d15f4 to your computer and use it in GitHub Desktop.
PHP Classes: when to use :: vs. ->
This file contains 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 | |
/** | |
* 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