* @license PHP License * @package WB * @subpackage base */ /** * StdClass * * Very basic class. * * @version 0.1.0 * @package WB * @subpackage base */ class WBStdClass { /** * list of object ids * @see getObjectId() * @var array */ static private $_objectIds = array(); /** * my object id * @var string */ protected $_myObjectId = null; /** * to String * * @return string */ public function __toString() { return $this->getObjectId(); } /** * receive unique id of this object * * Loves to use {@link spl_object_hash()} but also provides a * workaround using class name and counter. * * @return string onject id */ public function getObjectId() { // return cached object id if( $this->_myObjectId ) { return $this->_myObjectId; } // use SPL function to receive object id if( function_exists( 'spl_object_hash' ) ) { $this->_myObjectId = spl_object_hash( $this ); return $this->_myObjectId; } /** * Start workaround using self::$_objectIds * * Build oject id from class name * and append static counter */ $clazz = get_class( $this ); if( !isset( self::$_objectIds[$clazz] ) ) { self::$_objectIds[$clazz] = 0; } ++self::$_objectIds[$clazz]; $this->_myObjectId = $clazz . ':' . self::$_objectIds[$clazz]; return $this->_myObjectId; } /** * Debug Print * * Auxillary function to print debug messages on stdout * * @param mixed something to print * @param int minimum debug level to print */ protected function debugPrint($out, $level = 1) { if (WBParam::get('wb/debug', 0) < $level) { return; } $clazz = get_class($this); if (!is_scalar($out)) { $out = print_r($out, true); } $ts = gmdate('H:i:s'); fwrite(STDERR, sprintf("%s %s: %s\n", $ts, $clazz, $out)); flush(); } }