Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP5 Fatal errors


rgbargie

Recommended Posts

Posted

I am in the process of moving an osC V2.2 site to a new hosting server. The old server was PHP4/MySQL4 and the new one is PHP5/MySQL5

 

I already hit the MySQL 5 LEFT JOIN errors and, with bigPhil's help, I think I have fixed these though I can't be confident as there are so many SQL SELECT statements scattered throughout the code.

 

I have now hit 'PHP Fatal error: Cannot access empty property' errors when trying to check out an order. By using the server error logs I have tracked these down to a group of files in catalog/includes/modules/shipping/ called: edivsat.php, divsmall.php, edivlarge.php, ediv.php, spec.php, divsmall.php. They all have a line:

 

$this->$pcode = MODULE_SHIPPING_EDIV_POSTCODES_1;

 

which I have corrected to:

 

$this->pcode = MODULE_SHIPPING_EDIV_POSTCODES_1;

 

by removing the $ before the class property pcode.

 

My concern is though that I may not have found all these problems and I don't want to switch over to the new site to let our customers find them for us. In particular, I found this bit of code in shopping_cart.php:

 

function unserialize($broken) {
     for(reset($broken);$kv=each($broken);) {
       $key=$kv['key'];
       if (gettype($this->$key)!="user function"){
       $this->$key=$kv['value'];
     }

 

Should I need to worry about this as well? It only appears to be called for PHP3 and earlier if I am not mistaken.

 

So my question is: Has anyone else experienced this class of problem and are there any other files I should be checking?

 

Thanks for your help in advance.

Posted

Hmm. Very interesting. Do you know exactly what version of PHP is being used? Does it work correctly when you remove the "$" signs?

 

Normally, a class variable (member) such as "pcode" would be referenced as $this->pcode. As $this->$var is used in a number of places, I suspect that "$var" is supposed to be replaced by a string with the actual class variable, and then processed in the normal way:

$var = 'pcode';
$this->$var = 'xyz';

would be the same as

$this->pcode = 'xyz';

I looked at the PHP documentation and they don't really address this issue. It's possible that you were just upgraded to 5.3.x (most recent stable release) and it has a bug in it. Or, this EDIV code has a bug in it. Or, PHP's behavior has (deliberately) changed and member names with "$" are no longer tolerated (the "$" ignored). Look and see if class member "pcode" exists, or if $pcode is a string that contains the actual member name. If it's the former, I'd call it a bug in the EDIV code. If it's the latter, I would say that PHP has a bug. If so, a workaround may be something like

eval("\$this->$pcode = MODULE_....");

 

The unserialize() member function certain seems to be using $key as a place to substitute the actual string with the member variable name. Changing it to $this->key would be wrong, as all the entries would be dumped into member "key".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...