Created
November 20, 2011 20:30
-
-
Save robap/1380847 to your computer and use it in GitHub Desktop.
Adding Object ID to objects using php5.4 traits
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 | |
trait ObjectId | |
{ | |
public function getObjectId() | |
{ | |
if(!isset($this->__objectId__)) { | |
$this->__objectId__ = uniqid(); | |
} | |
return $this->__objectId__; | |
} | |
} | |
class Foo | |
{ | |
use ObjectId; | |
} | |
$a = new Foo(); | |
$b = new Foo(); | |
echo "a " . $a->getObjectId() . "\n"; | |
echo "b " . $b->getObjectId() . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment