Forums / Bug Reports / Object of class upload could not be converted to string ... in attributes_controller

Object of class upload could not be converted to string ... in attributes_controller

Views: 2,858

Results 1 to 7 of 7
12 Jul 2016, 6:05 PM
#1
vasilt avatar

vasilt

New Zenner

Join Date:
Jan 2006
Posts:
44
Plugin Contributions:
0

Object of class upload could not be converted to string ... in attributes_controller

Just upgraded from 1.3.9 by fresh install and applying all customizations and language files as well as the CKEditor. When trying to edit prices of products in the attributes controller, page goes blank after hitting the update button.
The error log is:

[12-Jul-2016 20:00:15] Request URI:/cart/admin/attributes_controller.php?action=update_product_attribute&attribute_page=1&products_filter=157, IP address: .............
#1  trim(upload Object ([file] => attributes_image,[filename] => ,[destination] =>/home/company/public_html/cart/images/,[permissions] => 420,[extensions] => Array ([0] =>jpg,[1] => jpeg,[2] => gif,[3] => png,[4] => webp,[5] => flv,[6] => webm,[7] =>ogg),[tmp_filename] => ,[message_location] => direct)) called at [/home/company/public_html/cart/admin/includes/functions/general.php:441]
#2  zen_not_null(upload Object ([file] => attributes_image,[filename] => ,[destination] =>/home/company/public_html/cart/images/,[permissions] => 420,[extensions] => Array ([0] =>jpg,[1] => jpeg,[2] => gif,[3] => png,[4] => webp,[5] => flv,[6] => webm,[7] =>ogg),[tmp_filename] => ,[message_location] => direct)) called at [/home/company/public_html/cart/admin/includes/classes/upload.php:61]
#3  upload->parse() called at [/home/company/public_html/cart/admin/attributes_controller.php:445]

[12-Jul-2016 20:00:15] PHP Catchable fatal error:  Object of class upload could not be converted to string in /home/company/public_html/cart/admin/includes/functions/general.php on line 441

The reason seems to be that the function zen_not_null($value) in admin/includes/functions/general.php does not handle objects while we have this construct:

$attributes_image = new upload('attributes_image');
``` on line 442 in admin/attributes_controller.php

PHP Version 5.2.17 MySQL: 5.5.50
12 Jul 2016, 6:36 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Object of class upload could not be converted to string ... in attributes_controller

  1. I'd strongly encourage you to get your server upgraded to a more modern version of PHP now that you're using a ZC version that supports it.

  2. The symptom you've reported is probably a bug, and probably only occurs when you don't have an image set on the attribute and aren't trying to actually upload a new one.
    Here's a bandage which I think will work for you:
    /admin/includes/classes/upload.php
    change line 58 from:```
    'tmp_name' => (isset($GLOBALS[$this->file]) ? $GLOBALS[$this->file] : ''));

to:```
'tmp_name' => (isset($GLOBALS[$this->file]) && is_string($GLOBALS[$this->file]) ? $GLOBALS[$this->file] : ''));

And then test by updating those attributes, preferably one with... and one without ... an attribute image ;)

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

12 Jul 2016, 7:53 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Object of class upload could not be converted to string ... in attributes_controller

I've recently uploaded an attribute with and without an attribute image, but using a newer php version. While I haven't gone back (yet) to look at how the applicable file handling changed over the versions, are you thinking it to be a bug related to older PHP (reported to be compatible with this version of ZC), or a bug in general (not discovered when using php 5.6).

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Jul 2016, 8:03 PM
#4
drbyte avatar

drbyte

Sensei

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

Re: Object of class upload could not be converted to string ... in attributes_controller

In looking at the code I'm thinking it's a bug in general: if $_FILES isn't set (which is set when an actual upload exists, in modern PHP), then it looks for a very old HTTP_POST_FILES array (which won't exist in modern PHP), and then "else" is where the above code is failing ... because the tmp_name is getting set to a string value but is being passed a global object which happens to be named the same as the variable which is the instance of the upload class ... basically a circular loop. This class was inherited from osC back in 2003 and this particular section hasn't been touched but clearly needs an overhaul for modern use.

That said, I'm very surprised this hasn't come up a million times already ... cuz it's not an issue unique to PHP 5.2 nor PHP 7.

Maybe the OP has the deprecated "register_globals" enabled or something?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

13 Jul 2016, 11:39 AM
#5
vasilt avatar

vasilt

New Zenner

Join Date:
Jan 2006
Posts:
44
Plugin Contributions:
0

Re: Object of class upload could not be converted to string ... in attributes_controller

The quick-fix of DrByte did the job. Attributes image are disabled in admin so I tested only this alternative. Hopefully, I will manage to test with attributes images enabled in the next few days and I will let you know if any problems arise. The "register_globals" is off and I agree with DrByte that its really amazing that this bug-candidate hasn't come up a million times already.

13 Jul 2016, 11:44 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Object of class upload could not be converted to string ... in attributes_controller

vasilt:

The quick-fix of DrByte did the job. Attributes image are disabled in admin so I tested only this alternative. Hopefully, I will manage to test with attributes images enabled in the next few days and I will let you know if any problems arise. The "register_globals" is off and I agree with DrByte that its really amazing that this bug-candidate hasn't come up a million times already.
Mind also posting the first 80-100 lines of the php results seen from the admin when the version link/button is pressed? Perhaps there is something there that could help the good Dr. identify why those issues didn't appear (assuming knowing the why is of importance).

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

13 Jul 2016, 12:05 PM
#7
vasilt avatar

vasilt

New Zenner

Join Date:
Jan 2006
Posts:
44
Plugin Contributions:
0

Re: Object of class upload could not be converted to string ... in attributes_controller

Here is the PHP core configuration
Server OS: Linux 2.6.32-573.26.1.el6.x86_64 Server Date: 13/07/2016 14:55:25 Server Up Time: UnsupportedHTTP Server: ApachePHP Version: 5.2.17 (Zend: 2.2.0)PHP File Uploads: OnUpload Max Size: 256MPHP Memory Limit: 1024MPOST Max Size: 256MDatabase: MySQL 5.5.50-38.0-logDatabase Host: localhost (127.0.0.1)Database Date: 13/07/2016 14:55:25Database Data Size: 5,021 kBDatabase Index Size: 1,147 kBMySQL Slow Query Log Status: OnMySQL Slow Query Log File: /var/log/mysql/slow-query.logMySQL Mode: NO_ENGINE_SUBSTITUTION
Zen Cart
Zen Cart 1.5.5a
Database Patch Level: 1.5.5

PHP Version 5.2.17

System Linux 2.6.32-573.26.1.el6.x86_64 #1 SMP Wed May 4 00:57:44 UTC 2016 x86_64
Build Date Jun 4 2015 17:12:01
Configure Command './configure' '--prefix=/usr/local/php52' '--mandir=/usr/man' '--with-config-file-path=/usr/local/php52/lib' '--with-config-file-scan-dir=/usr/local/php52/etc' '--with-pear=/usr/local/php52/pear' '--with-libdir=lib64' '--enable-discard-path' '--enable-sigchild' '--enable-magic-quotes' '--with-db4' '--disable-force-cgi-redirect' '--disable-ipv6' '--with-openssl=/usr/local/openssl-1.0.1g' '--disable-fastcgi' '--with-zlib' '--with-zlib-dir' '--enable-bcmath' '--with-libexpat-dir=/usr' '--with-bz2' '--enable-calendar' '--with-curl' '--with-curlwrappers' '--enable-exif' '--enable-ftp' '--with-kerberos' '--with-gd' '--with-pspell' '--with-libedit' '--with-jpeg-dir' '--with-png-dir' '--with-xpm-dir' '--with-freetype-dir' '--with-t1lib' '--enable-gd-native-ttf' '--with-ttf' '--with-gettext' '--with-imap' '--with-imap-ssl' '--with-ldap' '--with-ldap-sasl' '--enable-mbstring' '--with-mcrypt' '--with-mhash' '--with-mysql' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli' '--with-ncurses' '--enable-pcntl' '--enable-sysvmsg' '--enable-sysvsem' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pgsql' '--with-readline' '--enable-shmop' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--enable-soap' '--enable-sockets' '--enable-wddx' '--enable-sqlite-utf8' '--with-tidy' '--with-xmlrpc' '--with-xsl=/usr/local/libxslt' '--with-libxml-dir=/usr/local/libxml2' '--enable-zip' '--enable-zend-multibyte'
Server API CGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /usr/local/php52/lib
Loaded Configuration File /usr/local/php52/lib/php.ini
Scan this dir for additional .ini files /usr/local/php52/etc
additional .ini files parsed /usr/local/php52/etc/extensions.ini
PHP API 20041225
PHP Extension 20060613
Zend Extension 220060519
Debug Build no
Thread Safety disabled
Zend Memory Manager enabled
IPv6 Support disabled
Registered PHP Streams compress.zlib, compress.bzip2, dict, ftp, ftps, gopher, http, https, imap, imaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp, php, file, data, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, sslv3, sslv2, tls
Registered Stream Filters zlib., bzip2., convert.iconv., string.rot13, string.toupper, string.tolower, string.strip_tags, convert., consumed, http.*

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with the ionCube PHP Loader v5.0.7, Copyright (c) 2002-2015, by ionCube Ltd.
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

Configuration

PHP Core

Directive Local Value Master Value
allow_call_time_pass_reference On On
allow_url_fopen On On
allow_url_include Off Off
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_globals_jit Off Off
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
detect_unicode On On
disable_classes no value no value
disable_functions no value no value
display_errors Off STDOUT
display_startup_errors Off Off
doc_root no value no value
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_string no value no value
error_log ......................................... php_errorlog
error_prepend_string no value no value
error_reporting 6135 6133
expose_php Off Off
extension_dir /usr/local/php52/lib/php/extensions /usr/local/php52/lib/php/extensions
file_uploads On On
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors Off On
ignore_repeated_errors On On
ignore_repeated_source On On
ignore_user_abort Off Off
implicit_flush Off Off
include_path .:/usr/local/php52/pear .:/usr/local/php52/pear
log_errors On On
log_errors_max_len 0 1024
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
mail.force_extra_parameters no value no value
max_execution_time 60 180
max_file_uploads 20 20
max_input_nesting_level 64 64
max_input_time 180 180
memory_limit 1024M 1024M
open_basedir no value no value
output_buffering no value no value
output_handler no value no value
post_max_size 256M 256M
precision 14 14
realpath_cache_size 16K 16K
realpath_cache_ttl 120 120
register_argc_argv Off Off
register_globals Off Off
register_long_arrays On On
report_memleaks On On
report_zend_debug On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from no value no value
sendmail_path /usr/sbin/sendmail -t -i /usr/sbin/sendmail -t -i
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
stats_collector no value no value
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 256M 256M
upload_tmp_dir no value no value
user_dir no value no value
variables_order GPCS GPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On
zend.ze1_compatibility_mode Off Off