note 87422 deleted from function.spl-object-hash by sobak

From: Date: Tue, 22 Nov 2016 08:20:07 +0000
Subject: note 87422 deleted from function.spl-object-hash by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207472@lists.php.net to get a copy of this message
Note Submitter: Rafael M. Salvioni ---- The follow function is a implementation of the PHP´s function spl_object_hash(), unavailable in versions less 5.2.0. But, the algorithm of this function is different of the original PHP´s function. (Sorry... my english is very bad...) <?php if (!function_exists('spl_object_hash')) { /** * Returns the hash of the unique identifier for the object. * * @param object $object Object * @author Rafael M. Salvioni * @return string */ function spl_object_hash($object) { if (is_object($object)) { ob_start(); var_dump($object); $dump = ob_get_contents(); ob_end_clean(); if (preg_match('/^object\(([a-z0-9_]+)\)\#(\d)+/i', $dump, $match)) { return md5($match[1] . $match[2]); } } trigger_error(__FUNCTION__ . "() expects parameter 1 to be object", E_USER_WARNING); return null; } } ?>

« previous php.notes (#207472) next »