Robin, I've just have had a look at the last version of your parser. Here is some PHP3 problems i've noticed:
- function must be declared before they are called. Then, for example, you can't call "PMA_sqlParser_ArrayAdd_Timer()" in the "PMA_sqlParser_ArrayAdd()" function because the former is declared after the latter; - "include_once" and "require_once" are PHP4 functions; - "===" and "!==" are PHP4 operators.
Some coding standard fixes also :
- settings of function should be separated by ", " (comma plus a space character);
- keywords for control structures should be separated from the condition by a space ie: if (condition) { do some stuff } else { do some stuff }
- function names should not contain escaped charcters except after the "PMA" prefix ie "PMA_number_inrange()" should be "PMA_numberInRange".
I've modified your "sqlparse.php3" file in order it fits PEAR coding standards (excpet comments for function) and may run with PHP3. But I can't test it before the end of the week. You'll find it attached to this message.
Loïc
______________________________________________________________________________ ifrance.com, l'email gratuit le plus complet de l'Internet ! vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP... http://www.ifrance.com/_reloc/email.emailif
On Mon, 22 Jul 2002, Div Lo�c wrote:
Robin, I've just have had a look at the last version of your parser. Here is some PHP3 problems i've noticed:
- function must be declared before they are called. Then, for example, you can't call "PMA_sqlParser_ArrayAdd_Timer()" in the "PMA_sqlParser_ArrayAdd()" function because the former is declared after the latter;
How does one deal with recursive functions then ? PMA_sqlParser_isEscaped() used to be recursive, but I found it slightly faster as iterative (not that much).
- "include_once" and "require_once" are PHP4 functions;
- "===" and "!==" are PHP4 operators.
How does one then properly evaluate some expressions? $f = FALSE; $g = 0
($f == FALSE) -> true ($g == FALSE) -> true ($f === FALSE) -> true ($g === FALSE) -> false
My code relies on this difference, as some of the PHP functions (strpos namely) return FALSE for not found, and integers [0-strlen).
In that case, a 0 is the first position of the string, which is distinctly different from FALSE.
One of your changes: function PMA_sqlParser_strInStr($needle,$haystack) { - return (strpos($haystack,$needle) !== FALSE); -} + return (strpos(' ' . $haystack, $needle) > 0); +} // end of the "PMA_sqlParser_strInStr()" function
Actually breaks the function, stopping it from recognizing some things.
Some coding standard fixes also :
settings of function should be separated by ", " (comma plus a space character);
keywords for control structures should be separated from the condition by a space ie: if (condition) { do some stuff } else { do some stuff }
Tell me what text editor you are using with what settings, so that I can work out settings for my vim to do this properly.
The one major problem I've had with all auto-indenting in vim so far is that sometimes it seems to get out of sync at the end of an array, leaving me with an extra level of indentation.
- function names should not contain escaped charcters except after the "PMA" prefix ie "PMA_number_inrange()" should be "PMA_numberInRange".
Ok, I was going to be renaming all of the functions anyway.
I've modified your "sqlparse.php3" file in order it fits PEAR coding standards (excpet comments for function) and may run with PHP3. But I can't test it before the end of the week. You'll find it attached to this message.
Your changes _broke_ it on PHP4, so there isn't a chance it work.
Robin Johnson wrote:
On Mon, 22 Jul 2002, Div Loïc wrote:
Robin, I've just have had a look at the last version of your parser. Here is some PHP3 problems i've noticed:
- function must be declared before they are
called. Then, for example, you can't call "PMA_sqlParser_ArrayAdd_Timer()" in the "PMA_sqlParser_ArrayAdd()" function because the former is declared after the latter;
How does one deal with recursive functions then ? PMA_sqlParser_isEscaped() used to be recursive, but I found it slightly faster as iterative (not that much).
I don't think this is a problem in PHP3: when you call a function from within itself, is has been declared at a higher point in the source.
- "include_once" and "require_once" are PHP4
functions;
- "===" and "!==" are PHP4 operators.
How does one then properly evaluate some expressions? $f = FALSE; $g = 0
($f == FALSE) -> true ($g == FALSE) -> true ($f === FALSE) -> true ($g === FALSE) -> false
My code relies on this difference, as some of the PHP functions (strpos namely) return FALSE for not found, and integers [0-strlen).
In that case, a 0 is the first position of the string, which is distinctly different from FALSE.
The is_integer() test will give false on $f and true on $g. Not funny but is works. is_bool() in a PHP4 function.
One of your changes: function PMA_sqlParser_strInStr($needle,$haystack) {
- return (strpos($haystack,$needle) !== FALSE);
-}
- return (strpos(' ' . $haystack, $needle) > 0);
+} // end of the "PMA_sqlParser_strInStr()" function
Actually breaks the function, stopping it from recognizing some things.
It's a trick to avoid having a 0 in first position, but I guess the is_integer() trick can be used.
On Mon, 22 Jul 2002, Div Lo�c wrote:
Some coding standard fixes also :
- function names should not contain escaped charcters except after the "PMA" prefix ie "PMA_number_inrange()" should be "PMA_numberInRange".
I have a request to make of the list. In the interests of keeping the code seperate, and having managable functin names, are sub-prefixes permissiable to better indicate the seperation of code ?
Eg for my Parser The prefix could be either PMAsqp_ or PMA_SQP_
(I'd go for the second one, as it is still compliant with the PEAR naming conventions http://pear.php.net/manual/en/standards.naming.php)
As things stand, I have been using PMA_sqlParser_* for functions specific to the parser PMA_str_* for functions dealing with strings and PMA_* for functions not directly specific to the parser (the character type matching for example).
I've modified your "sqlparse.php3" file in order it fits PEAR coding standards (excpet comments for function) and may run with PHP3. But I can't test it before the end of the week. You'll find it attached to this message. From seeing your work, I've made most of the changes in my own codebase
with the suggestions from the list.