Implode Function stopped working

Discussion in 'PHP' started by goneinsane, Jul 26, 2013.

  1. #1
    I changed hosts and all of a sudden my implode code stopped working. It says "Warning: implode() [function.implode]: Invalid arguments passed in (webpage address here) on line 53". Please see my code below.

    if ('cp_features' == $metarow['meta_key'] && $metarow['meta_value'])
               
               
                    $feature_items = implode(', ',$feature_array);
                    if(!empty($feature_array)) {
                    $features = "<li>Features: <font color=#21adf0>" . $feature_items . "</font></li>";
                    }
           
                    
    Code (markup):
    I tried adding this code below and the error went away but then it messed up my feature list.

    $feature_array = array();
    Code (markup):
     
    goneinsane, Jul 26, 2013 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    Well, seems like that $feature_array is not an array or it doesn't exist.

    You can easily check if $feature_array is an array with the is_array() function. If it's not an array, check where it's initialized.
     
    GMF, Jul 26, 2013 IP
  3. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #3
    No it doesn't exist but it's always worked fine regardless.
    What can I do to fix it?
     
    goneinsane, Jul 26, 2013 IP
  4. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #4
    Well, if it doesn't exist, you have a problem.


    I don't know the whole code, but the array $feature_array is important. Without it, the code you provided is pretty much useless.

    So: Go into your code and search for the place where the array $feature_array is created. Probably reads from a database or something.
     
    GMF, Jul 26, 2013 IP
  5. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #5
    I've searched the code and the database and it's not there. Feature_items is in the database.
    Not sure how it's worked for the past few years on one host and now at the new host it doesn't.
     
    goneinsane, Jul 26, 2013 IP
  6. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #6
    Well, sadly, I cannot help you further.

    While changing hosts, something had to go missing (file deleted?). I really can't know....

    Try to contact the guy that wrote the script (if it's well-known software, they have a forum or support), or add a database query, that creates the $feature_array and fills it with the right values.
     
    GMF, Jul 26, 2013 IP
  7. t3od0r

    t3od0r Well-Known Member

    Messages:
    334
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    155
    #7
    What you get is a Warning, so most probably error reporting was disabled on the old host
     
    t3od0r, Jul 26, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    Or didn't exist because your old host was still running PHP 3 instead of PHP 5.

    Why do I say PHP3? I see some telltales of it being that old, in which case it's probably bug-ridden insecure filth that needs a complete rewrite. The mere presence of a FONT tag screams that, but I see other bits of logic disconnects that raise questions...

    Like no closing bracket, so only the implode is run by that first condition?

    As GMF said I suspect we'd need to see more than a little snippet. Snippets are cute, but really end up like trying to do brain-surgury over a time-phone to 1887.

    I SUSPECT the logic should be something more like this:
    if 
    	('cp_features' == $metarow['meta_key'] &&
    	$metarow['meta_value']  &&
    	isset($feature_array) &&
    	is_array($feature_array) &&
    	!empty($feature_array)
    ) {
    	$features = '
    		<li>
    			Features:
    			<span>'.implode(', ',$feature_array).'</span>
    		</li>';
    }
    
    Code (markup):
    Though I'm guessing WILDLY as I have no clue as to the contents of any of those values, or where that IF statement is in the middle of everything or even when/where the code around it is opened/closed.
     
    deathshadow, Jul 26, 2013 IP
  9. goneinsane

    goneinsane Well-Known Member

    Messages:
    303
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #9
    Thanks to everyone for your help.
    I put a "@" in front of the function so it hides the warning message since everything appears to be working correctly. It's a temporary fix until I can get someone to look at it closer.
    Thanks.
     
    goneinsane, Jul 26, 2013 IP