PHP on windows ERROR in assigment of stdClass object

PHP on windows ERROR in assigment of stdClass object

by Pierre Pichet -
Number of replies: 3

If you are adminitrating a moodle installation on a windows system, you should read this notice and do the suggested test.
This is related to PHP interpretation of the code of moodle.

If you code something like
$ac = new stdClass;
$ac->options = "uniform:1:10:3";
$ad = $ac;
$ac->options = "uniform:1:1000:3";
you expect, as PPH is a transparent language, that
$ac->options contains  "uniform:1:1000:3"; and
$ad->options contains  "uniform:1:10:3"; .
This is what you will find using the PHP with moodle on Unix.

I found surprisingly that on my computer moodle windows version using the complete installation package from moodle.org (I retest it by downloading the today available  PHP version ) , the code don't work and
$ac->options contains  "uniform:1:1000:3"; and
$ad->options contains  also "uniform:1:1000:3"; .

The explanation is that this PHP for windows does not create a new objet $ad but just gave to the variable $ad a pointer to $ac.

The assigment is working properly on arrays but not on class objects. The PHP should be recompiled with the correct options and a test should be included in moodle to check that the PHP used by moodle correctly assign stdClass object.

You could see a test file working properly on a unix moodle installation at
http://www.chimie.uqam.ca/moodle/testassignPHP.php

and the result obtained on my computer (windows installation) at

http://www.chimie.uqam.ca/moodle/Result_testing_PHP_windows_assigment_.htm

the attachment  contains the file for testing your system.

I have submit the bug related to this problem.
This is somewhat a silent bug difficult to notice so this is why I submitted it in this forum so that everyone using moodle in windows could be aware of the problem even if there is no evident installation symptoms...

Average of ratings: -
In reply to Pierre Pichet

Re: PHP on windows ERROR in assigment of stdClass object

by Rob Barreca -
Just to note...that first line should be $ac = new stdClass();

I think the difference is probably in PHP 4 vs. PHP 5, not windows vs. unix.

In PHP 4, setting $object1 = $object2 always cloned $object2 unless you specified =& to actually reference that object.

In PHP 5, setting $object1 = $object2 makes $object1 point to $object2 unless you do a $object1 = clone($object2).
In reply to Rob Barreca

Re: PHP on windows ERROR in assigment of stdClass object

by Pierre Pichet -

Perhaps, this was due to the fact that this is PHP5 that is installed in my computer ( and I notice that PHP5 is used in the new package from moodle.org) and I should use clone function.

Nevertheless, the clone function is not implemented in the actual moodle code when there is such an assignment.

And the code writen for PHP4 has not been revised to check and add the necessary or not clone() function.

Is the actual implementation of 1.6 uses the comment like

// $Id: edit.php,v 1.64.2.6 2005/09/14 11:09:32 mindforge Exp $

to modify the code when it is interpreted by PHP5?

Is everybody aware of this problem ?

In reply to Pierre Pichet

Re: other comments

by Pierre Pichet -

I have a useful exchange in the bug report with petr dot skoda at vslib.cz which explains that all the code for 1.6 should be written in PHP5 and that the assigment in PHP5  follows the rules as explain by the preceeding response from Rub Barreca.

The necessity of using PHP5 for moodlle 1.6 is an information that is not easy to know as there are no instructions about PHP5 in the developper docs on coding.
http://docs.moodle.org/en/Coding

and even if you put PHP5 in the search engine in the docs...

Should we have an indication in the upper part of the .php files indicating that it has been reviewed for PHP 5 coding?