Zen Cart Logo
Forums / Bug Reports / [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

[Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Locked

Views: 19,630

Results 1 to 20 of 21
This thread is locked. New replies are disabled.
27 Sep 2012, 10:57 PM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,872
Plugin Contributions:
7

[Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

This is an informational post...hopefully it will save someone else the time I spent on this.

After upgrading my local Windows 7 test server to Xampp 1.80: php 5.4.4 I started getting debug logs being created from the admin.

[27-Sep-2012 16:10:25 UTC] PHP Warning: Creating default object from empty value in D:\blah blah\public_html\tienda\MY_ADMIN\categories.php on line 1018

Which is:

                  if (empty($pInfo->products_id)) {
line 1018         $pInfo->products_id= $pID;

It happens in Admin->Catalog->Categories/Products when doing a search that yields a result that includes categories (but for no result/a result with products only,..no debug log is created).

I have a copy of my shop (upgraded to 1.51) and a vanilla 1.51 install on the same server. The vanilla install did not cause the debug log.

As it was “obviously” a problem with my shop I spent a lot of time investigating that avenue...nothing.

The error reporting seemed to be the same in the shop files and ZC151 files, and php.ini between the old Xampp 1.73 php 5.3.1. and the new 1.80 php 5.4.4.

Eventually I found that in php 5.4 the buggers have included E_STRICT error reporting in E_ALL so the warnings were from E_STRICT being implemented: obvious when you work with php all the time..which I don’t.

Further to this adding the extra line cures the warning.

  if (empty($pInfo->products_id)) {
$pInfo = new stdClass();	
$pInfo->products_id= $pID;

So....why does the vanilla ZC151 not produce the error? Obviously there's an E_ALL lurking somewhere in my files but I’ve looked at all the instances of E_ALL in my shop and the vanilla, and commented out any extras in my mods...still haven’t found why there is a difference in the error reporting...so this post does not go in the bug reports!

30 Sep 2012, 3:37 PM
#2
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,865
Plugin Contributions:
3

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

moved to bug reports forum.

Will investigate and schedule a fix where necessary.

23 Nov 2012, 5:33 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,085
Plugin Contributions:
56

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Also occurs for /admin/products_price_manager.php:

[22-Nov-2012 16:18:43 Europe/Berlin] PHP Warning:  Creating default object from empty value in C:\xampp\htdocs\v1.5.1\myadmin\products_price_manager.php on line 476

[22-Nov-2012 16:18:43 Europe/Berlin] PHP Warning:  Creating default object from empty value in C:\xampp\htdocs\v1.5.1\myadmin\products_price_manager.php on line 482
3 Dec 2012, 2:39 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,085
Plugin Contributions:
56

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Also occurs for /includes/modules/shipping_estimator.php:

[25-Nov-2012 16:22:21 Europe/Berlin] PHP Warning:  Creating default object from empty value in C:\xampp\htdocs\mystore\includes\modules\shipping_estimator.php on line 107
[27-Nov-2012 17:29:35 Europe/Berlin] PHP Warning:  Creating default object from empty value in C:\xampp\htdocs\mystore\includes\modules\shipping_estimator.php on line 117

It looks like the solution for this one might be (starting at line 63 of the v1.5.1 module):

  //if($cart->get_content_type() !== 'virtual') {
  require(DIR_WS_CLASSES . 'order.php');
  $order = new order;
  if ($_SESSION['customer_id']) {
    // user is logged in
    if (isset($_POST['address_id'])){
      // user changed address
      $sendto = $_POST['address_id'];
    }elseif ($_SESSION['cart_address_id']){
      // user once changed address
      $sendto = $_SESSION['cart_address_id'];
      //        $sendto = $_SESSION['customer_default_address_id'];
    }else{
      // first timer
      $sendto = $_SESSION['customer_default_address_id'];
    }
    $_SESSION['sendto'] = $sendto;
    // set session now
    $_SESSION['cart_address_id'] = $sendto;
    // set shipping to null ! multipickjup changes address to store address...
    $shipping='';
    // include the order class (uses the sendto !)
//    require(DIR_WS_CLASSES . 'order.php');
//    $order = new order;
  }else{
    // user not logged in !
15 Jan 2013, 8:42 PM
#6
kamino84 avatar

kamino84

New Zenner

Join Date:
Aug 2006
Posts:
80
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

I think we can consider this minor as it doesnt seem to have caused any issues on any of our sites but our host 1and1.com is requiring everyone to upgrade to php 5.4 before April 1st, and when doing so the myDEBUG files in the cache folder start growing like crazy with these warnings.

I have not edited any of these core files.

PHP Warning: Creating default object from empty value in /homepages/38/d436025994/htdocs/includes/modules/payment/authorizenet_aim.php on line 429

This error in the authorize module refers to this line in the admin_notifications function $aimdata->fields = array();

PHP Warning: Illegal string offset 'id' in /homepages/38/d436025994/htdocs/includes/modules/payment/paypalwpp.php on line 199

This refers to the update_status function and this line of code: $sql = $db->bindVars($sql, ':countryId', $order->billing['country']['id'], 'integer');

Again neither core files have been touched. And these errors do not show if we revert back to PHP 5.3.

If you have a quick fix to keep the log files from getting crazy (other than shutting it off) please let me know.

15 Jan 2013, 9:23 PM
#7
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

To address these warnings, add the highlighted changes to your code:

Kamino84:

PHP Warning: Creating default object from empty value in /homepages/38/d436025994/htdocs/includes/modules/payment/authorizenet_aim.php on line 429

  function admin_notification($zf_order_id) {
    global $db;
    $output = '';
[B]    $aimdata = new stdClass;[/B]
    $aimdata->fields = array();

Kamino84:

PHP Warning: Illegal string offset 'id' in /homepages/38/d436025994/htdocs/includes/modules/payment/paypalwpp.php on line 199

  function update_status() {
    global $order, $db;
//    $this->zcLog('update_status', 'Checking whether module should be enabled or not.');
    if ($this->enabled && (int)$this->zone > 0[B] && isset($order->billing['country']['id'])[/B]) {
15 Jan 2013, 9:39 PM
#8
kamino84 avatar

kamino84

New Zenner

Join Date:
Aug 2006
Posts:
80
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Thanks for the quick reply and fix. As mentioned before I dont think it was causing an problems with the software functioning just a log file mess when they start to stack up. It appears php 5.4 is a bit more strict with the calling of objects and error logging.

6 Feb 2013, 9:12 PM
#9
rozdesignz avatar

rozdesignz

Zencart Website Owner

Join Date:
Aug 2011
Location:
Tampa Bay, Florida USA
Posts:
17
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

:blink:
[07-Feb-2013 05:33:03 Australia/Melbourne] PHP Warning: Creating default object from empty value in /homepages/../../htdocs/store/includes/modules/shipping_estimator.php on line 117

thanks, Lora

6 Feb 2013, 9:28 PM
#10
rozdesignz avatar

rozdesignz

Zencart Website Owner

Join Date:
Aug 2011
Location:
Tampa Bay, Florida USA
Posts:
17
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

it also has the same error message for line 117, 107, 92

7 Feb 2013, 1:21 PM
#11
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,085
Plugin Contributions:
56

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

rozdesignz:

it also has the same error message for line 117, 107, 92
See post #5.

6 Sep 2013, 7:19 PM
#12
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,872
Plugin Contributions:
7

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

I find this solution as posted in post #5 to cause a problem in the shipping estimator when there are multiple addresses.
After selecting an address in the pull-down, the page refreshes and the selected address is maintained in the drop-down but the displayed address in incorrect. Tested with two addresses in a new install of 1.51.

//if($cart->get_content_type() !== 'virtual') {
require(DIR_WS_CLASSES . 'order.php');
$order = new order;
if ($_SESSION['customer_id']) {
// user is logged in
if (isset($_POST['address_id'])){
// user changed address
$sendto = $_POST['address_id'];
}elseif ($_SESSION['cart_address_id']){
// user once changed address
$sendto = $_SESSION['cart_address_id'];
// $sendto = $_SESSION['customer_default_address_id'];
}else{
// first timer
$sendto = $_SESSION['customer_default_address_id'];
}
$_SESSION['sendto'] = $sendto;
// set session now
$_SESSION['cart_address_id'] = $sendto;
// set shipping to null ! multipickjup changes address to store address...
$shipping='';
// include the order class (uses the sendto !)
// require(DIR_WS_CLASSES . 'order.php');
// $order = new order;
}else{
// user not logged in !

31 Oct 2013, 10:41 PM
#13
countrycharm avatar

countrycharm

Totally Zenned

Join Date:
Jul 2007
Posts:
2,179
Plugin Contributions:
2

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

lat9:

Also occurs for /admin/products_price_manager.php:

[22-Nov-2012 16:18:43 Europe/Berlin] PHP Warning: Creating default object from empty value in C:\xampp\htdocs\v1.5.1\myadmin\products_price_manager.php on line 476

[22-Nov-2012 16:18:43 Europe/Berlin] PHP Warning: Creating default object from empty value in C:\xampp\htdocs\v1.5.1\myadmin\products_price_manager.php on line 482


Hey lat9 did you find a solution for this? Thank you
10 Nov 2013, 5:51 AM
#14
kevin205 avatar

kevin205

Totally Zenned

Join Date:
Dec 2012
Posts:
607
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Any fix on this problem?

12 Nov 2013, 2:53 PM
#15
vanhorn_s avatar

vanhorn_s

Zen Follower

Join Date:
Apr 2010
Posts:
283
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Try this one. I found it in the ozpost thread:

includes/modules/shipping_estimator.php
Add to line 46:

 require_once('includes/classes/http_client.php'); // shipping in basket
//PHP5.4 fix
$order = new stdClass();
/*
// moved below and altered to include Tare
  // totals info
  $totalsDisplay = '';
21 Jun 2014, 4:46 PM
#16
reneetje avatar

reneetje

New Zenner

Join Date:
Jun 2009
Posts:
42
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

I have this one coming up...what do I have to do of the above options to get rid of it (zen 1.5.1 - php 5.4) ?

[21-Jun-2014 16:31:31 Europe/Amsterdam] PHP Warning:  Creating default object from empty value in D:\www\dynamitemagic.nl\www\shop\includes\modules\shipping_estimator.php on line 92

Also I have a different error log from a payment module (icepay), anyone any idea how to solve it?

[21-Jun-2014 16:46:17 Europe/Amsterdam] PHP Warning:  Creating default object from empty value in D:\www\dynamitemagic.nl\www\shop\includes\modules\payment\icepay.php on line 550
[21-Jun-2014 16:46:17 Europe/Amsterdam] PHP Warning:  Creating default object from empty value in D:\www\dynamitemagic.nl\www\shop\extras\icepay\notify.php on line 75

Line 545-572 of ICEPAY.PHP are this:

	function OnPostback()
	{
		if ( $_SERVER['REQUEST_METHOD'] != 'POST' ) return false;
		
		$this->postback 						= NULL;
		$this->postback->status					= $_POST['Status'];
		$this->postback->statusCode				= $_POST['StatusCode'];
		$this->postback->merchant				= $_POST['Merchant'];
		$this->postback->orderID				= $_POST['OrderID'];
		$this->postback->paymentID				= $_POST['PaymentID'];
		$this->postback->reference				= $_POST['Reference'];
		$this->postback->transactionID			= $_POST['TransactionID'];
		$this->postback->consumerName			= $_POST['ConsumerName'];
		$this->postback->consumerAccountNumber	= $_POST['ConsumerAccountNumber'];
		$this->postback->consumerAddress		= $_POST['ConsumerAddress'];
		$this->postback->consumerHouseNumber	= $_POST['ConsumerHouseNumber'];
		$this->postback->consumerCity			= $_POST['ConsumerCity'];
		$this->postback->consumerCountry		= $_POST['ConsumerCountry'];
		$this->postback->consumerEmail			= $_POST['ConsumerEmail'];
		$this->postback->consumerPhoneNumber	= $_POST['ConsumerPhoneNumber'];
		$this->postback->consumerIPAddress		= $_POST['ConsumerIPAddress'];
		$this->postback->amount					= $_POST['Amount'];
		$this->postback->currency				= $_POST['Currency'];
		$this->postback->duration				= $_POST['Duration'];
		$this->postback->paymentMethod			= $_POST['PaymentMethod'];
		$this->postback->checksum				= $_POST['Checksum'];
		
		$this->doLogging( sprintf("Postback: %s", serialize($_POST)) ); 

Lines 64-87 of NOTIFY are these:

	if ($notifyCustomer){
		// Load order data
		$order_totals = $ICE_module->load_session($ICE_module->orderID);
		
		include_once(DIR_WS_CLASSES . 'order.php');
		
		// Override default setting
		$_SESSION['payment'] = 'icepay';
		$GLOBALS['icepay']->title = $ICE_module->postback->paymentMethod;		
		
		// Retrieve order
		$order = new order($ICE_module->orderID);
			
		// E-mail setup
		for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
		$order->total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
		$order->total_tax += zen_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
		$order->total_cost += $total_products_price;

The payments do come in and work but the error is created anyway since php 5.4. Maybe anyone can tell if they see anything strange as I am not familiar with any of the php-code :)

Thanks!

René

21 Jun 2014, 5:07 PM
#17
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,085
Plugin Contributions:
56

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

I'm pretty sure on the first one, try changing to the following:

	function OnPostback()
	{
		if ( $_SERVER['REQUEST_METHOD'] != 'POST' ) return false;
		
		$this->postback 						= new stdClass();
		$this->postback->status				= $_POST['Status'];
		$this->postback->statusCode				= $_POST['StatusCode'];
		$this->postback->merchant				= $_POST['Merchant'];
		$this->postback->orderID				= $_POST['OrderID'];
		$this->postback->paymentID				= $_POST['PaymentID'];
		$this->postback->reference				= $_POST['Reference'];
		$this->postback->transactionID			= $_POST['TransactionID'];
		$this->postback->consumerName			= $_POST['ConsumerName'];
		$this->postback->consumerAccountNumber	= $_POST['ConsumerAccountNumber'];
		$this->postback->consumerAddress		= $_POST['ConsumerAddress'];
		$this->postback->consumerHouseNumber	= $_POST['ConsumerHouseNumber'];
		$this->postback->consumerCity			= $_POST['ConsumerCity'];
		$this->postback->consumerCountry		= $_POST['ConsumerCountry'];
		$this->postback->consumerEmail			= $_POST['ConsumerEmail'];
		$this->postback->consumerPhoneNumber	= $_POST['ConsumerPhoneNumber'];
		$this->postback->consumerIPAddress		= $_POST['ConsumerIPAddress'];
		$this->postback->amount					= $_POST['Amount'];
		$this->postback->currency				= $_POST['Currency'];
		$this->postback->duration				= $_POST['Duration'];
		$this->postback->paymentMethod			= $_POST['PaymentMethod'];
		$this->postback->checksum				= $_POST['Checksum'];
		
		$this->doLogging( sprintf("Postback: %s", serialize($_POST)) );

The second one's a bit different; I'm assuming that my counting is correct and that line 75 is this one:

$order = new order($ICE_module->orderID);

Based on that, my best guess is the the $ICE_module object doesn't include an orderID element.

21 Jun 2014, 5:31 PM
#18
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

Reneetje:

I have this one coming up...what do I have to do of the above options to get rid of it (zen 1.5.1 - php 5.4) ?

PHP Warning: Creating default object from empty value in \includes\modules\shipping_estimator.php on line 92

<https://github.com/zencart/zencart/commit/fe411c439a807820504797732db2a714a7c850cf>
21 Jun 2014, 7:56 PM
#19
reneetje avatar

reneetje

New Zenner

Join Date:
Jun 2009
Posts:
42
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

@Dr. Byte

Thank you, I replaced the entire file with the github version, now see if it works....

@Lat9

Also Thank you! If I fix the first file but not the second (as I do not know how to), can I break the plugin? Otherwise I will leave it like it is for now.

I also emailed the people at ICEPAY to make the module for php5.4 a few days ago but did not get a reply yet.

Mmmm....I will wait if I get a reply from icepay and then see what to do, do you think the error is created before going to the icepay-paymentpage or on the postback?

Then I know what to test :)

René

7 Dec 2014, 3:18 AM
#20
ksivv avatar

ksivv

New Zenner

Join Date:
Nov 2014
Location:
London
Posts:
15
Plugin Contributions:
0

Re: [Done v1.5.4] PHP 5.4 PHP Warning: Creating default object from empty value

torvista:

if (empty($pInfo->products_id)) {
$pInfo = new stdClass();
$pInfo->products_id= $pID;

I using ZC v 1.5.1 and got exactly the same error 
```php
PHP Warning:  Creating default object from empty value in /home2/footy/public_html/xxxx/categories.php on line 1015

but adding the line didn't fix the problem. Error only happens when product set to Priced by Attributes. No errors for products without attributes.

Please advise.