Voting

: three minus one?
(Example: nine)

The Note You're Voting On

dave dot zap at gmail dot com
17 years ago
Take care using the backtrace method to find the calling class of a static method, you should step backward through the array and find a match for your getInstance() function. In backtrace the class name you want is not always the last item in the array.

I will not post the whole singleton class here, but have made the following modification to Frederik Krautwald's method (found below)

<?php
$bt
= debug_backtrace();
// this method is count($bt)-1) by Frederik will fall over when calling getInstance from within an include file.
//$class = $bt[count($bt) - 1]['class'];

for( $i=count($bt)-1 ; $i > 0 ; $i--)
{
if(
$bt[$i]['function'] == 'getInstance')
{
$class = $bt[$i]['class'];
break;
}
}
?>

<< Back to user notes page

To Top