Jump to content


Corporate Sponsors


Latest News: (loading..)

- - - - -

array_merge problems in PHP5.2.x


23 replies to this topic

#1 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 23 November 2007, 17:38

The oscommerce is full of array_merge the osc developers couldn't live without this peace of code.

Due to changes of PHP language structure, you need to update all the code with array_merge.

example:

Quote

if ((!isset($_GET['bID']) || (isset($_GET['bID']) && ($_GET['bID'] == $pages['pages_id']))) && !isset($bInfo) && (substr($action, 0, 3) != 'new')) {
$bInfo_array = array_merge($pages, $info);
$bInfo = new objectInfo($bInfo_array);
}

change to:

Quote

if ((!isset($_GET['bID']) || (isset($_GET['bID']) && ($_GET['bID'] == $pages['pages_id']))) && !isset($bInfo) && (substr($action, 0, 3) != 'new')) {
$bInfo_array = array_merge((array)$pages, (array)$info);
$bInfo = new objectInfo($bInfo_array);
}

According to PHP manual:
http://uk2.php.net/array_merge

The behaviour of array_merge() was modified in PHP 5. Unlike PHP 4, array_merge() now only accepts parameters of type array. However, you can use typecasting to merge other types. See the example below for details.



Example 258. array_merge() PHP 5 example

<span class="default"><?php
   $beginning </span><span class="keyword">= </span><span class="string">'foo'</span><span class="keyword">;
   </span><span class="default">$end </span><span class="keyword">= array(</span><span class="default">1 </span><span class="keyword">=> </span><span class="string">'bar'</span><span class="keyword">);
   </span><span class="default">$result </span><span class="keyword">= </span><span class="default">array_merge</span><span class="keyword">((array)</span><span class="default">$beginning</span><span class="keyword">, (array)</span><span class="default">$end</span><span class="keyword">);
   </span><span class="default">print_r</span><span class="keyword">(</span><span class="default">$result</span><span class="keyword">);
   </span><span class="default">?></span>
The above example will output:

  Array
   (
	   [0] => foo
	   [1] => bar
   )

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#2 CRUZN8R

  • Community Member
  • 9 posts
  • Real Name:Mike Challis

Posted 24 February 2008, 01:48

OK, where in OSC needs to be modified? What files where?

#3 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 05 April 2008, 14:14

View PostCRUZN8R, on Feb 24 2008, 02:48 AM, said:

OK, where in OSC needs to be modified? What files where?

In the following files:

/catalog/admin/
banner_manager.php
categories.php
configuration.php
customers.php
manufacturers.php
orders.php
orders_status.php
reviews.php
specials.php

/catalog/admin/includes/clases/
emails.php

/catalog/admin/includes/functions/
compatibility.php
general.php

/catalog/includes/clases/
emails.php
http_client.php

/catalog/includes/functions/
compatibility.php

/catalog/includes/modules/payment/
paypal_uk_direct.php
paypal_uk_express.php
Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#4 Coopco

  • Community Member
  • 9,557 posts
  • Real Name:Leslie Cooper
  • Gender:Male
  • Location:Sea Lake, Victoria, Australia

Posted 06 April 2008, 07:53

Thanks for posting web-project, a great time saver.


The Coopco Underwear Shop



If you live to be 100 years of age, that means you have lived for 36,525 days. Don't waste another, there aren't many left.

#5 GemRock

  • Community Member
  • 2,069 posts
  • Real Name:Ken
  • Gender:Male
  • Location:UK

Posted 06 April 2008, 14:15

the rc versions (at least RC2a) do not seem to have this issue?

Ken
commercial support - unProtected channel, not to be confused with the forum with same name - open to everyone who need some professional help: either PM/email me, or go to my website (URL can be found in my profile).
over 20 years of computer programming experience.

#6 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 06 April 2008, 16:45

View PostGemRock, on Apr 6 2008, 03:15 PM, said:

the rc versions (at least RC2a) do not seem to have this issue?

Ken

for older versions as most of users are still using the 2.2
Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#7 Coopco

  • Community Member
  • 9,557 posts
  • Real Name:Leslie Cooper
  • Gender:Male
  • Location:Sea Lake, Victoria, Australia

Posted 07 April 2008, 08:22

View Postweb-project, on Apr 7 2008, 02:45 AM, said:

for older versions as most of users are still using the 2.2
And for some of the contributions.


The Coopco Underwear Shop



If you live to be 100 years of age, that means you have lived for 36,525 days. Don't waste another, there aren't many left.

#8 ladiessymbol

  • Community Member
  • 24 posts
  • Real Name:Olga

Posted 27 September 2008, 20:51

View PostCoopco, on Apr 7 2008, 03:22 AM, said:

And for some of the contributions.


in the above files I have noticed the array's... do I change it for everyone of them in the files or specific one's?

http://forums.oscommerce.com/index.php?showtopic=316064

Edited by ladiessymbol, 27 September 2008, 20:52.


#9 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 27 September 2008, 21:22

View Postladiessymbol, on Sep 27 2008, 09:51 PM, said:

in the above files I have noticed the array's... do I change it for everyone of them in the files or specific one's?

http://forums.oscommerce.com/index.php?showtopic=316064

in your screen shot example you are on the customers (customers.php) page. You have 2 choices: 1) update/patch the arrays or 2) upgrade to new version of oscommerce.
Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#10 ladiessymbol

  • Community Member
  • 24 posts
  • Real Name:Olga

Posted 27 September 2008, 22:43

View Postweb-project, on Sep 27 2008, 04:22 PM, said:

in your screen shot example you are on the customers (customers.php) page. You have 2 choices: 1) update/patch the arrays or 2) upgrade to new version of oscommerce.


this is what I found in customer.php:

$reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers['customers_id'] . "'");
$reviews = tep_db_fetch_array($reviews_query);

$customer_info = array_merge($country, $info, $reviews);

$cInfo_array = array_merge($customers, $customer_info);
$cInfo = new objectInfo($cInfo_array);
}


If I am correct I would change it to:

$reviews_query = tep_db_query("select count(*) as number_of_reviews from " . TABLE_REVIEWS . " where customers_id = '" . (int)$customers['customers_id'] . "'");
$reviews = tep_db_fetch_array($reviews_query);

$customer_info = array_merge((array)$country, (array)$info, (array)$reviews);

$cInfo_array = array_merge((array)$customers, (array)$customer_info);
$cInfo = new objectInfo($cInfo_array);
}

I can only assume...

I have never done coding... please let me know.. :)

#11 geoffreywalton

  • Community Sponsor
  • 7,729 posts
  • Real Name:Geoffrey Walton
  • Gender:Male
  • Location:Norfolk, UK (close to the centre of the universe)

Posted 28 September 2008, 07:34

Rather than get every coding change "approved" take a back up ofthe files you are going to change.

Make the change.

Test it.

If it works, great, otherwise restore the backup and no damage done.
Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

Virus Threat Scanner
My Contributions
Basic install answers.
Click here for Contributions / Add Ons.
UK your site.
Site Move.
Basic design info.

For links mentioned in old answers that are no longer here follow this link Useful Threads.

If this post was useful, click the Like This button over there ======>>>>>.

#12 ladiessymbol

  • Community Member
  • 24 posts
  • Real Name:Olga

Posted 28 September 2008, 20:29

View Postgeoffreywalton, on Sep 28 2008, 02:34 AM, said:

Rather than get every coding change "approved" take a back up ofthe files you are going to change.

Make the change.

Test it.

If it works, great, otherwise restore the backup and no damage done.

So I added the (array) into the file like above....

and now I have this on the Jon Doe profile it does not show on the other two customer profiles...

[img]http://www.ladiessymbol.com/temp/Snapshotjondoe.jpg[/img]


if the below code is correct? Do I need to do the same on the object_info.php?

Edited by ladiessymbol, 28 September 2008, 20:41.


#13 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 28 September 2008, 21:17

View Postgeoffreywalton, on Sep 28 2008, 08:34 AM, said:

Rather than get every coding change "approved" take a back up ofthe files you are going to change.

Make the change.

Test it.

If it works, great, otherwise restore the backup and no damage done.

Exactly the same I mean in my second line of the signature.

To: ladiessymbol
I did the whole patch of arrays (as described earlier - few posts above) as one of my software applications running on the oscommerce 2.2 Milestone 2 with huge amount of contributions/modules & it's working without any issues on PHP 5.2.x

Simply backup and patch also the following files:
/catalog/admin/includes/functions/

compatibility.php
general.php
Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#14 Vger

  • Community Member
  • 16,978 posts
  • Real Name:R Anthony
  • Gender:Not Telling

Posted 28 September 2008, 22:52

We have hundreds of osCommerce 2.2 MS2 websites running on PHP 5.2.6, and the only problems experienced have been the way that PHP 5.2.6 handles commenting out of php and html. Old code which was commented out but left in place has caused problems.

More of a problem for osCommerce is when hosts, as part of the upgrade to PHP 5.2+, turn off Register Long Arrays in php.ini. So that all of the entries for $HTTP_POST_VARS etc. have to be changed to their shortened form.

For the longer term Register Long Arrays and Register Globals won't even be available in PHP 6 when it comes out.

Another thing that is disabled by default in PHP 5.2+ is gpc_magic_quotes, and this causes problems for some osCommerce add-ons if turned off.

Vger

#15 richcduk

  • Community Member
  • 13 posts
  • Real Name:rich

Posted 23 June 2009, 18:36

Thanks for this, fixed a bug in my shop. :thumbsup:

#16 mycreativewishes

  • Community Member
  • 88 posts
  • Real Name:Joe Randoph

Posted 03 August 2009, 20:26

I tried this and the problem still exists as follows:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/logoread/public_html/admin/customers.php on line 733

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/logoread/public_html/admin/customers.php on line 733

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/logoread/public_html/admin/customers.php on line 735

Warning: reset() [function.reset]: Passed variable is not an array or object in /home/logoread/public_html/admin/includes/classes/object_info.php on line 17

Warning: Variable passed to each() is not an array or object in /home/logoread/public_html/admin/includes/classes/object_info.php on line 18
How do I fix this? Maybe I'm misunderstanding. I changed the code as suggested and still get this warning when I go to customers in the admin section.

Joe

#17 web-project

  • Community Member
  • 4,310 posts
  • Real Name:Alex
  • Gender:Male
  • Location:Hertfordshire, UK

Posted 07 January 2010, 17:22

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /home/logoread/public_html/admin/customers.php on line 733

Quote

$customer_info = array_merge((array)$country, (array)$info, (array)$reviews);

Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/logoread/public_html/admin/customers.php on line 735

Quote

$cInfo_array = array_merge((array)$customers, (array)$customer_info);

Edited by web-project, 07 January 2010, 17:23.

Please read this line: Do you want to find all the answers to your questions? click here. As for contribution database it's located here!
8 people out of 10 don't bother to read installation manuals. I can recommend: if you can't read the installation manual, don't bother to install any contribution yourself.
Before installing contribution or editing/updating/deleting any files, do the full backup, it will save to you & everyone here on the forum time to fix your issues.
Any issues with oscommerce, I am here to help you.

#18 mfsumption

  • Community Member
  • 6 posts
  • Real Name:Michael

Posted 15 November 2010, 18:49

View Postweb-project, on 05 April 2008, 14:14, said:

In the following files:

/catalog/admin/
banner_manager.php
categories.php
configuration.php
customers.php
manufacturers.php
orders.php
orders_status.php
reviews.php
specials.php

/catalog/admin/includes/clases/
emails.php

/catalog/admin/includes/functions/
compatibility.php
general.php

/catalog/includes/clases/
emails.php
http_client.php

/catalog/includes/functions/
compatibility.php

/catalog/includes/modules/payment/
paypal_uk_direct.php
paypal_uk_express.php

We have an old OSC installation and our ISP updated PHP on our server and we got the array_merge errors as mentioned in this thread. I am new to OSC and PHP, but I managed to update all of the files mentioned in the quote above except for the two compatibilty.php files. The only mention of array_merge in these two files is the actual function itself, so I wasn't sure what to specifically update in these two files? Any help? Thanks.

#19 rabon33

  • Community Member
  • 51 posts
  • Real Name:jason ravone

Posted 01 July 2011, 23:26

I have the fallowing issues
Warning: in_array() [function.in-array]: Wrong datatype for second argument in public_html/seret/admin25xrt/edit_orders.php on line 441

Warning: in_array() [function.in-array]: Wrong datatype for second argument in public_html/seret/admin25xrt/edit_orders.php on line 441

Warning: Cannot modify header information - headers already sent by (output started at html/seret/admin25xrt/edit_orders.php on line 441 in html/seret/admin25xrt/includes/functions/general.php on line 22

according to this warnings the file says:

		    //save ot_skippy from certain annihilation
			 if ( (!in_array($ot_class, $written_ot_totals_array)) && (!in_array($ot_title, $written_ot_titles_array)) && (tep_not_null($ot_value)) && (tep_not_null($ot_title)) && ($ot_class != 'ot_tax') && ($ot_class != 'ot_loworderfee') ) { //7
			//this is supposed to catch the oddball components that don't show up in $order_totals



i tried to fix it canging to this:
                //save ot_skippy from certain annihilation

 if ( (!in_array((array)$ot_class, (array)$written_ot_totals_array)) && (!in_array((array)$ot_title, (array)$written_ot_titles_array)) && (tep_not_null($ot_value)) && (tep_not_null($ot_title)) && ($ot_class != 'ot_tax') && ($ot_class != 'ot_loworderfee') ) { //7

        //this is supposed to catch the oddball components that don't show up in $order_totals


but no luck... how can i make it work

thanks

Edited by rabon33, 01 July 2011, 23:29.


#20 andes1

  • Community Member
  • 181 posts
  • Real Name:andrea pataquiva diaz

Posted 02 July 2011, 01:16

It says the second instance of the array...

Warning: in_array() [function.in-array]: Wrong datatype for second argument

Place this:

//save ot_skippy from certain annihilation
if ( (!in_array($ot_class, (array)$written_ot_totals_array)) && (!in_array($ot_title, (array)$written_ot_titles_array)) && (tep_not_null($ot_value)) && (tep_not_null($ot_title)) && ($ot_class != 'ot_tax') && ($ot_class != 'ot_loworderfee') ) { //7
//this is supposed to catch the oddball components that don't show up in $order_totals

TEST IT and let us know.