Skip to content

Instantly share code, notes, and snippets.

@robap
Created November 20, 2011 20:30
Show Gist options
  • Save robap/1380847 to your computer and use it in GitHub Desktop.
Save robap/1380847 to your computer and use it in GitHub Desktop.
Adding Object ID to objects using php5.4 traits
<?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