i got error to make a class object

See all posts Reply

i got error to make a class object new!
by manish, 16 years, 6 months ago
hi,

when i use this class in PHP 5.2 then i got error

Object of class upload could not be converted to string in C:\wamp\www\newproject\upload.php on line 13

but the same class run on php 5.0,

please clear me what the problem?????

thx in advanceReply
Re: i got error to make a class object new!
by colin, 16 years, 6 months ago
What is the actual line 13 in your code?Reply
Re: i got error to make a class object new!
by manish, 16 years, 5 months ago
the actually code is on line 13.....

$handle = new Upload($_FILES['user_img']);

but i got error only php5.2 not php 5 why??????

thanks in advanceReply
Re: i got error to make a class object new!
by colin, 16 years, 5 months ago
Apparently, it is an issue with PHP 5.2;

As of (at least) PHP 5.2, you can no longer convert an object to a string unless it has a __toString method. Converting an object without this method now gives the error: Object of class could not be converted to string in <file> on line <line>

I have PHP 5.2.3 here, but the class works fine. However, if I do the following at the command line, I have the problem:
$ php -r "echo PHP_VERSION; echo new StdClass;"
5.2.3-1ubuntu6
Catchable fatal error: Object of class stdClass could not be converted to string in Command line code on line 1

What are the lines before and after your line 13? Also, which version of the class are you using?Reply
Re: i got error to make a class object new!
by manish, 16 years, 5 months ago
my complete code ,

if ($_POST['action'] == 'local') {
  $handle = new Upload($_FILES['user_img']);
  $handle->mime_check = false;
  $handle->allowed = array("image/bmp",
                           "image/gif",
                           "image/jpeg",
                           "image/png",
                           "image/jpg");
  if ($handle->uploaded) {
    $handle->image_resize          = true;
    $handle->image_ratio           = true;
    $handle->image_y               = 106;
    $handle->image_x               = 100;
    $handle->file_name_body_add = '_'.$current_userid;
    $handle->Process('./user_image/');
    $upload_image_name = $handle->file_dst_name;
  }	

  if($upload_image_name=='') {
    //business logic
  } else {
    //business logic
  }
}
Reply