Undefined clone() function in locallib.php

Undefined clone() function in locallib.php

by Chris M -
Number of replies: 7
I'm farely new to Moodle and just experimenting with it (to see if we can use it), but when I make a question for a quiz and I want to preview it it returns an error:

Fatal error: Call to undefined function: clone() in [...]\moodle\mod\quiz\locallib.php on line 1226

I just downloaded the latest 1.5dev version today. There are more occurences of clone() in that file.

Regards, Chris

Average of ratings: -
In reply to Chris M

Re: Undefined clone() function in locallib.php

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
clone() should be defined in lib/moodlelib.php for PHP4 (and is native in PHP5) .... what exact version of PHP are you using?

if(!check_php_version('5.0.0')) {
eval('
    function clone($obj) {
        return $obj;
    }
');    
}  

In reply to Martin Dougiamas

Re: Undefined clone() function in locallib.php

by Zbigniew Fiedorowicz -
Perhaps some installations have eval disabled for security reasons?  See the following post:
http://moodle.org/mod/forum/discuss.php?d=23288&parent=110619
In reply to Zbigniew Fiedorowicz

Re: Undefined clone() function in locallib.php

by John Papaioannou -
As far as I can remember, if you disable eval(), then Blocks won't work. So it's not that, probably.
In reply to Martin Dougiamas

Re: Undefined clone() function in locallib.php

by Chris M -
I think I have found the little bugger. My php version is 4.3.10. Here the function check_php_version in lib/moodlelib.php (line 4870) comes to nothing: it returns (4310 >= 500) and that of course is true. So moodle thinks I have a version higher than 5.0.0, which is not the case. Should I file a bug report? (If so, where and how?)

Regards, Chris

In reply to Chris M

Re: Undefined clone() function in locallib.php

by James Depow -

Hi Chris,

I received basically the same error and posted it in the bug tracker (bug 3176).

I received back a request to modify a few things and will do so after my 11:20 class (Atlantic Daylight Time, GMT -3) and retry.  I will post the results.  It should be in a couple of hours.

Jim

In reply to James Depow

Re: Undefined clone() function in locallib.php

by James Depow -
Hi Chris,

As a follow-up, I was advised to change moodlelib.php (in the lib folder).
From:
if(!check_php_version('5.0.0')) {
// the eval is needed to prevent PHP 5 from
getting a parse error!
eval('
    function clone($obj) {
        return
$obj;
    }
');
}

To:
    function clone($obj) {
        return
$obj;
    }
It workedbig grin

Thanks to the Moodle team,

Jim