can't have a database table called 'class' [message #1943] |
Mon, 09 February 2009 10:46 |
ikatz
Messages: 40 Registered: December 2007 Location: Durham, NH
|
Member |
|
|
This problem seems pretty obvious in hindsight, but I created a table called "class", which causes Radicore to generate a class file with the name "class" -- a syntax error.
I would suggest adding some sort of check for table names that won't translate to PHP classes, when they are first imported into the dictionary. Or, rather than making a list of words that are reserved, it might be easier to just run "php -l" on each generated file.
I don't mind correcting my own naming errors (to fix my problem, I'm renaming "class" to "course"); my concern is that the Radicore application generates PHP scripts that don't parse.
|
|
|
|
Re: can't have a database table called 'class' [message #1946 is a reply to message #1945] |
Mon, 09 February 2009 11:42 |
ikatz
Messages: 40 Registered: December 2007 Location: Durham, NH
|
Member |
|
|
No problem!
function isThisAGoodName($tablename)
{
//short version requires PECL extension
//return runkit_lint ("<?php class $tablename {} ?" . ">");
//"long" version
$temp_file = tempnam(sys_get_temp_dir(), 'rad');
file_put_contents($temp_file, "<?php class $tablename {} ?>");
$result = `php -lq $temp_file`;
unlink($temp_file);
return 0 === strpos($result, "No syntax errors detected");
}
|
|
|