#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    7
    Rep Power
    0

    Errors due to changing to php v5.4.3


    Hi gurus

    Recently i upgrade to wamp 2.22 with php v5.4.3 instead of the older php v5.3.13. With this, due to strict error reporting, many errors pop up. After fixing the error

    "Only variables should be assigned by reference"

    a new error relating to "Array to string conversion" pops up, the rogue line is shown below. There are numerous error in this code flag by php v5.4.13

    $newvalue = array_diff_assoc($headnow[$now], isset($options['headerbefore'][$now]) ? $options['headerbefore'][$now] : array());

    2 Questions
    1. How best to fix this code?
    2. Where to learn about changes require to avoid these problems?

    Appreciate help & guidance
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    The only thing that looks like it could raise the error is $now. What is its exact value?

    2. The problem is not you upgrading to 5.4 but you using new settings that no longer hide these errors from you. Meaning you had the problematic code earlier but weren't being told about it.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    as usual, it's a combination of sloppy programming and the rotten internals of PHP.

    As the PHP manual points out, array_diff_assoc() converts the values into strings before comparing them. If the values happen to be arrays, they're converted into the string "Array". Yeah, the string representation of an array is actually the word "Array". Since this obviously leads to total nonsense in most cases, you get a warning. In your case, the whole comparison doesn't work, because PHP compares "Array" with "Array" (which is of course equal) instead of actually looking into the arrays.

    This problem has always existed and isn't related to PHP 5.4.3 in any way. It's just that now those errors surface.



    Originally Posted by FuzMic
    1. How best to fix this code?
    You'll have to use a loop, I fear.



    Originally Posted by FuzMic
    2. Where to learn about changes require to avoid these problems?
    As I already said, this has nothing to do with the different versions.

    But as a general rule for writing PHP code: Always study the PHP manual very carefully before using a function. There's plenty of pitfalls and counter-intuitive behaviour, so don't expect a function to simply work. For example, a coworker of mine just recently stumbled upon array_unique(), which suffers from the same string conversion issues like your function (but at least it has a flag to turn the conversion off).

    Comments on this post

    • requinix agrees : yep, the documentation definitely says that... bah!
    Last edited by Jacques1; July 12th, 2013 at 07:59 PM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    7
    Rep Power
    0
    Thanks guys for huge effort - salutation from the novice in php & alike, world changing too fast for old guys.
    The errors came from codes from Joomla Extensions, good to learn to try to fix them. Cheers!!

IMN logo majestic logo threadwatch logo seochat tools logo