1

I hope you can help me. I have this error in my php code and I cant figure out what do I need to change and where. It is showing that in this line where it in stars.

Here is my code:

private function replaceFile($id, $file, $version) {

    global $CFG;
    $source = get_record('procedure_log','procedure_id', $id);
    $destination = $CFG->dataroot . "/procedures/$id/$version/";
    @mkdir($destination, 0777, true);
    $dataobject = new stdClass();
    $dataobject->id = $this->logId;
    $dataobject->file = addslashes($destination . $file['name']);
    **copy(var_dump($source.$file['name'], $destination.$file['name'] ));**
}
Erika
  • 23
  • 7
  • You need to learn how to [READ and debug](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) error messages. Everything you needed to solve the problem was in the error message. Somewhere you are trying to use an object as if it was a string maybe $source for instance – Anigel Aug 01 '13 at 08:39
  • see this: http://stackoverflow.com/questions/5032687/php-catchable-fatal-error-object-of-class-stdclass-could-not-be-converted-to-s – mr.soroush Aug 01 '13 at 08:47

2 Answers2

1

$source is probably object and you can't use it as string (you tried to do it by joining with $file['name'] string using dot). You should select what you want to add to this string.

Elon Than
  • 9,603
  • 4
  • 27
  • 37
  • 1
    Not sure how they can add __toString() to stdClass – Anigel Aug 01 '13 at 08:41
  • @Anigel Right, he can't :) But he can specify what he want to add to string. – Elon Than Aug 01 '13 at 08:45
  • I need file from the object $source copy to the $destination file. Sorry, I am new in php. An I am she :D – Erika Aug 01 '13 at 08:50
  • @Erika I can't edit previous comment to change that "he" ;) Try to use `$source->file` and in case of problems check what you'll see after writing `var_dump($source);`. – Elon Than Aug 01 '13 at 08:55
  • Thank you Elon. I still learning this bloody php :) Thanks again and dont worry about he :D It is not a problem :D – Erika Aug 01 '13 at 08:59
  • @Elon. I am not getting anymore fatal error, just trying to find out why my copy function is not working :) Thanks again :) – Erika Aug 01 '13 at 09:20
  • @Erika I think it's because you are using `var_dump` with `copy`. Skip it and its brackets. – Elon Than Aug 01 '13 at 09:24
  • @Erika And now it's ok? ;) BTW. Remove `@` from `mkdir` and check if `$source->file` contains proper folder path (with trailing slash). – Elon Than Aug 01 '13 at 09:32
  • @Elon. I checked, it contains proper folder, just still not making cop. So now Ill create a new procedure and Ill check again. Also I removed @ from mkdir :) – Erika Aug 01 '13 at 09:39
1

You function get_record probably returning the object not a string that your assigning in the variable $source. You need to check that what is the value of $source variable by echoing it.

And you will get your exact problem.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75