Use case
Even though PHP 5.3 is already out since more than one and a half year, a lot of web-hosters still don’t provide this version. In one of my projects I had to deal with the webhoster all-inkl. The project is written in PHP 5.3, but all-inkl supports PHP 5.2 only. Indeed they offer the possibility to use CGI version for PHP >5.2, but that doesn’t make me happy. So I tried to downgrade the project as successfull as possible.. But when it comes to 5.3′s Late Static Binding I faced problems to rebuild this functionality within 5.2. But after hours of searching the web and testing each approaches, I wrote my own hunky-dory function to fake LSB.
Solution
if( !function_exists( 'get_called_class' ) ) { class class_tools { static $i = 0; static $fl = null; static function get_called_class() { $bt = debug_backtrace(); if( self::$fl == $bt[2]['file'].$bt[2]['line'] ) { self::$i++; } else { self::$i = 0; self::$fl = $bt[2]['file'].$bt[2]['line']; } $lines = file($bt[2]['file']); preg_match_all( '/([a-zA-Z0-9\_]+)::'.$bt[2]['function'].'/', $lines[$bt[2]['line']-1], $matches ); return $matches[1][0]; } } function get_called_class() { return class_tools::get_called_class(); } }
Conclusion
This faked LSB gets only included if no native support for get_called_class exists (PHP <5.3). Otherwise the parser won’t recognize this code. Even though a lot of code examples don’t deal with the second index of the debug_backtrace-result ($bt[2]), for me it was/is the only way to make that LSB work correctly.
Thanks for sharing the information
https://piofront.com/
https://airmasteremirates.com/
https://airmastertape.com/
https://awesomedrive.ae/
https://brazilfloors.com/
Thanks, you saved my day :)
Thanks ;)