Search code examples
phpapacheubuntulamp

Why is only one server throwing the error "Array to String Conversion"?


Here is the code that is causing the error:

        foreach($_GET['Inventory'] as $fld => $val) {
           print_r("Field: " . $fld . " Value: " . $val . '</br>');
            if($val != '' && !is_null($val))
                if($fld != 'searchoption')
                    $perma .=  $fld . '=' . $val . '&';
        } 

print_r() is the cause of the error, but I'm only getting this error on one server. This server recently went through a new installation of Ubuntu (upgraded to 14.04 fresh install) and LAMPP. This is the same (as far as I can tell) source code as the other ones are running, but for some reason this error is persistent here.

I'm not familiar with php-apache modules and I can't shake the feeling that the system is missing a core component that will fix this.

EDIT (more info): One on server instead of throwing an error it displays "Array" in the place of the array, if there is indeed an array in $val. I'm not looking to change the code, but rather find out what might cause this.

OUTPUT FROM THE WORKING SERVER AFTER DOING A SEARCH:

Field: searchoption Value: Array
Field: parentBarcode Value:
Field: barcode Value:
Field: room Value:
Field: fixedAssetTag Value:
Field: hostDomainName Value:
Field: ipAddress Value: test
Field: macAddress Value:
Field: serialNumber Value:
Field: purchaseOrder Value:
Field: accountNumber Value:
Field: searchscope Value: 1

EDIT: The source codes are exactly the same on both servers.

Loaded Apache modules on not working server:

//both servers have these modules loaded
=   core_module (static)                        
=   so_module (static)      
=   http_module (static)
=   log_config_module (static)
=   logio_module (static)
=   alias_module (shared)
=   auth_basic_module (shared)
=   authn_file_module (shared)
=   authz_host_module (shared)
=   authz_user_module (shared)
=   autoindex_module (shared)
=   cgi_module (shared)
=   deflate_module (shared)
=   dir_module (shared)
=   env_module (shared)
=   mime_module (shared)
=   mpm_prefork_module (shared)
=   negotiation_module (shared)
=   php5_module (shared)
=   setenvif_module (shared)
=   status_module (shared)

//Server with error has these extra modules loaded
+   authz_core_module (shared)
+   authn_core_module (shared)
+   version_module (static)
+   unixd_module (static)
+   access_compat_module (shared)
+   rewrite_module (shared)     
+   watchdog_module (static)
+   filter_module (shared)

//Working server has these extra modules loaded
- authz_groupfile_modeul (shared)
- authz_default_module (shared)
- reqtimeout_module (shared)

Solution

  • The error likely exists on both servers: you're trying to output an array as a string. This is the problem you should fix. You're probably only seeing the error message on one server because this server has a stricter setting for the PHP configuration variable error_reporting.

    I'd suggest separating the logger line into something like:

    print_r($fld);
    print_r($val);
    

    which will work regardless of the variable types.