When on the main administrative section (www.mydomain.com/moodle/admin/index.php), I receive errors (listed above the administration stuff) about blocks. The errors are as follows:
/**** Start errors ****/
Block activity_modules: class does not have a constructor
Block admin: class does not have a constructor
Block calendar_month: class does not have a constructor
Block calendar_upcoming: class does not have a constructor
Block course_list: class does not have a constructor
Block course_summary: class does not have a constructor
Block news_items: class does not have a constructor
Block online_users: class does not have a constructor
Block participants: class does not have a constructor
Block recent_activity: class does not have a constructor
Block search_forums: class does not have a constructor
Block section_links: class does not have a constructor
Block social_activities: class does not have a constructor
/**** End errors ****/
The following is then listed every time:
Updating blockinfo for course: Carroll Online()
Updating blockinfo for course: CMS 102()
Updating blockinfo for course: CMS 101()
Firstly, I do not understand why the errors are being thrown. Although, I am using PHP5 (which uses __construct() as the standard constructor), it allows for class name constructors for backwards compatibility. Secondly, why is it trying to update blockinfo each time I go to the administrative section?
Any ideas? I would greatly appreciate any help.
--Nicole
I found that the error was originating from an error in the upgrade_blocks_plugins() function in blocklib.php. The function checks through the blocks listed in the /blocks directory. For each block it checks that certain methods (namely the constructor) in the block class is there. The errant code is:
if( !in_array(strtolower($classname), $methods)) {
//No constructor
$notices[] = "Block $blockname: class does not have a constructor";
$invalidblocks[] = $blockname;
continue;
}
The problem is the code lower cases the classname it checks for in the methods array, but the constructor names have upper case letters. So obviously, it doesn't "find" the constructor name in the array, and outputs the notice. Once I removed the strtolower() function, blocks were detected and added to the database (which it had never done previously as there were no blocks in the database).
Hope this helps someone else.
--Nicole
Hi Nicole,
This error is caused by the object system change in PHP 5. In PHP5, functions that return class and method names return them case sensitive, changing the PHP4 behavior where they were always returned in lower case. To begin with, that's why you get these errors.
Now, if you take the strtolower() call out of the check, the code will function just fine for you but will break for users of PHP 4 so that's no general solution either. The correct way would be to array_walk() the $methods array and make them all lowercase before the checks.
I 'll put this in CVS in a few days (bit short of time right now). It's just that up to this point, with no official PHP5 out there is not much feedback to identify these issues. So thank you for reporting this!
Regards, Jon