Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP tries to Autoload Random Class Name

A customer of mine is reporting an odd problem with some code in their Magento system (Magento is an ecommerce platform written in PHP). I don't have direct access to the system to poke around and debug, so I thought I'd ask Stack Overflow if you've ever seen anything like this.

The error they're occasionally seeing is

Warning: include(O1ucm02owqn3iwwcx5osz2m2.php): failed to open stream: 

With a call stack that includes

#0 /Users/theirusername/Sites/project/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(O1ucm02...', '/Users/theiruse...', 93, Array)
#1 /Users/theirusername/Sites/project/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('o1ucm02owqn3iww...')
#3 [internal function]: spl_autoload_call('o1ucm02owqn3iww...')
#4 /Users/theirusername/Sites/project/app/code/local/Theirname/Commercebug/Model/Observer.php(191): defined('Mage_Core_Block...')

From this, I can deduce that PHP thinks it needs to instantiate a class named O1ucm02owqn3iwwcx5osz2m2. However, I can't figure out why PHP might be doing this. The lines that trigger the error (#4 in the callstack, around line 191 in Observer.php) should be

if(defined("Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS"))
{
    $path = Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS;
}

These lines don't seem to mention any PHP class named O1ucm02owqn3iwwcx5osz2m2 (I say "should be" because the customer's deployed the code themselves, I'm working with them to get a copy to look for potential problems).

Does anyone have any idea what might be going on? Is this a a known PHP bug/issue with some version and/or has anyone seen an issues like this with PHP autoloaders/defined/class constants?

(I'm working with my customer to determine the version of PHP they're running, as well as getting a copy of the files they've deployed to ensure they match what I assume are there.)

like image 214
Alan Storm Avatar asked Nov 15 '12 17:11

Alan Storm


1 Answers

The defined() function serves as a compliment to the define() function for named constants. That is to say, constants declared with define can be nicely checked with defined.

However, that code is checking a class constant, which while possible, is less typical. I suspect that the checking is triggering autoloading (just as the use of class_exists can trigger autoloading.) However, the value handed off to the autoloader through use of defined is mangled (perhaps handing off the hash of the z-val for the string.)

I'm wondering if the following change would get things working:

// force PHP to load the class first, then let defined() check for the constant
if(class_exists("Mage_Core_Block_Template") && defined("Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS"))
{
    $path = Mage_Core_Block_Template::XML_PATH_DEBUG_TEMPLATE_HINTS;
}

As Alan noted in his comment, Zend Guard could be causing an issue, too.

like image 183
AdamJonR Avatar answered Oct 09 '22 12:10

AdamJonR