Hi all!
Since many packages (wordpress, propel, horde, phing, etc.) use "import"
as either class or function name, and we couldn't find a good solution
to make it work with import keyword without going into all kinds of
troublesome hacks, so we are thinking about replacing 'import' keyword
with 'use' keyword, which is already reserved.
If you know any reason why this may be a problem - please speak now (or
forever hold your peace :). Please do not answer this email with
proposals to replace 'namespace' keyword with 'package', etc. - it will
be offtopic. For this topic please let's discuss only using keyword
'use' instead of 'import'.
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Stanislav Malyshev wrote:
Hi all!
Since many packages (wordpress, propel, horde, phing, etc.) use "import"
as either class or function name, and we couldn't find a good solution
to make it work with import keyword without going into all kinds of
troublesome hacks, so we are thinking about replacing 'import' keyword
with 'use' keyword, which is already reserved.If you know any reason why this may be a problem - please speak now (or
forever hold your peace :). Please do not answer this email with
proposals to replace 'namespace' keyword with 'package', etc. - it will
be offtopic. For this topic please let's discuss only using keyword
'use' instead of 'import'.
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to code the
patch tonight first to prove it works.
Greg
Hello Gregory,
even if you can solve it easily your patch will not solve the fact that we
won't have a token for that keyword the, or am i missing something?
marcus
Tuesday, October 23, 2007, 1:18:52 AM, you wrote:
Stanislav Malyshev wrote:
Hi all!
Since many packages (wordpress, propel, horde, phing, etc.) use "import"
as either class or function name, and we couldn't find a good solution
to make it work with import keyword without going into all kinds of
troublesome hacks, so we are thinking about replacing 'import' keyword
with 'use' keyword, which is already reserved.If you know any reason why this may be a problem - please speak now (or
forever hold your peace :). Please do not answer this email with
proposals to replace 'namespace' keyword with 'package', etc. - it will
be offtopic. For this topic please let's discuss only using keyword
'use' instead of 'import'.
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to code the
patch tonight first to prove it works.
Greg
Best regards,
Marcus
Marcus Boerger wrote:
Hello Gregory,
even if you can solve it easily your patch will not solve the fact that we
won't have a token for that keyword the, or am i missing something?marcus
Hi Marcus,
Just finished the patch (see separate reply), and in my tests, the
keyword still works as a keyword. So unless I'm not understanding your
question, yes, we will have a token for the keyword.
Greg
P.S. feel free to call me Greg :)
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to code the
patch tonight first to prove it works.
OK, please send it as soon as you have it :)
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Stanislav Malyshev wrote:
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to code the
patch tonight first to prove it works.OK, please send it as soon as you have it :)
Hi,
The attached patch is for PHP 5.3, if it is acceptable, I will port it
to PHP 6, which is not difficult, although it does involve a lot of
cut/pasting.
The patch does these things:
- fixes an unrelated bug I found in implementation of LSB - "static" is
not checked for in zend_do_import()/zend_do_namespace() and other places
that we check for "self" and "parent" - fixes a rather serious error in the fix for Bug #42859 - missing
parens in zend_do_import() - adds "import" and "namespace" as valid function/class names
- allows any string for method names, just as we allow any string for
variable names - fixes a bug in logic for $class->list where $class-> list (note the
whitespace between -> and list) returns aT_LIST
instead ofT_STRING
- It allows "import ::Classname as Blah" which is currently a parse error
- class constants are unchanged - reserved words still error out.
Note that the zend_compile.c fixes can all be committed directly as they
are all bugfixes and not related to the import/namespace/reserved words fix.
To implement this, I added several states to the lexer in order to
return T_STRING
whenever possible, which is after T_NEW, T_INTERFACE,
T_CLASS, T_EXTENDS
and in the T_IMPLEMENTS
list. In addition, after
T_FUNCTION
outside of a class, it returns T_STRING
for "import" and
"namespace" but no other reserved words. After T_FUNCTION
inside of a
class (method declaration), it returns T_STRING
for all possible
strings. After :: or -> T_STRING
is always returned. Also, rather than
take the approach LSB does with T_STATIC, I have the lexer initialize
the string value of T_IMPORT and T_NAMESPACE
so we can preserve case for
autoloading needs. The parser frees the unused char * when normal
import/namespace declarations are called.
In the parser, I use fully_qualified_class_name instead of
namespace_name for both import syntaxes. This introduces a minor issue
in that this is no longer a parse error:
import static::oops as Classname;
However, if "Classname" is used, this will simply result in "Fatal
error: Class 'static::oops' not found in..." and shouldn't be too big of
a deal. Also in the parser, I inserted T_IMPORT and T_NAMESPACE
as
aliases to T_STRING
in global situations to allow for static method
calls, class constants, and fully-qualified namespace calls.
Basically this script is now possible with the patch:
<?php
namespace import;
import ::Exception as Test;
function import() {echo 'import function';}
interface import {}
interface fooey {}
class Exception extends ::Exception implements fooey, import {}
class namespace {
const HI = 3;
function list() {echo METHOD;}
}
import();
var_dump(namespace::HI);
namespace::list();
?>
and results in this output:
cellog@lot-49:~/workspace/php5$ sapi/cli/php -n testme.php
import functionint(3)
import::namespace::list
I have not performed profiling on the patch, instead focusing on
correctness for now.
The patch looks complicated because of the additional states, but is
really not that complicated, honest.
:)
Greg
Hi,
sorry if I missed something but is there any reason to not use keyword "use"?
IMHO allowing keywords in class, method, function, etc. names brings
more confusion then value.
Stanislav Malyshev wrote:
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to code the
patch tonight first to prove it works.OK, please send it as soon as you have it :)
Hi,The attached patch is for PHP 5.3, if it is acceptable, I will port it
to PHP 6, which is not difficult, although it does involve a lot of
cut/pasting.The patch does these things:
- fixes an unrelated bug I found in implementation of LSB - "static" is
not checked for in zend_do_import()/zend_do_namespace() and other places
that we check for "self" and "parent"- fixes a rather serious error in the fix for Bug #42859 - missing
parens in zend_do_import()- adds "import" and "namespace" as valid function/class names
- allows any string for method names, just as we allow any string for
variable names- fixes a bug in logic for $class->list where $class-> list (note the
whitespace between -> and list) returns aT_LIST
instead ofT_STRING
- It allows "import ::Classname as Blah" which is currently a parse error
- class constants are unchanged - reserved words still error out.
Note that the zend_compile.c fixes can all be committed directly as they
are all bugfixes and not related to the import/namespace/reserved words fix.To implement this, I added several states to the lexer in order to
returnT_STRING
whenever possible, which is after T_NEW, T_INTERFACE,
T_CLASS,T_EXTENDS
and in theT_IMPLEMENTS
list. In addition, after
T_FUNCTION
outside of a class, it returnsT_STRING
for "import" and
"namespace" but no other reserved words. AfterT_FUNCTION
inside of a
class (method declaration), it returnsT_STRING
for all possible
strings. After :: or ->T_STRING
is always returned. Also, rather than
take the approach LSB does with T_STATIC, I have the lexer initialize
the string value of T_IMPORT andT_NAMESPACE
so we can preserve case for
autoloading needs. The parser frees the unused char * when normal
import/namespace declarations are called.In the parser, I use fully_qualified_class_name instead of
namespace_name for both import syntaxes. This introduces a minor issue
in that this is no longer a parse error:import static::oops as Classname;
However, if "Classname" is used, this will simply result in "Fatal
error: Class 'static::oops' not found in..." and shouldn't be too big of
a deal. Also in the parser, I inserted T_IMPORT andT_NAMESPACE
as
aliases toT_STRING
in global situations to allow for static method
calls, class constants, and fully-qualified namespace calls.Basically this script is now possible with the patch:
<?php
namespace import;
import ::Exception as Test;
function import() {echo 'import function';}
interface import {}
interface fooey {}
class Exception extends ::Exception implements fooey, import {}
class namespace {
const HI = 3;
function list() {echo METHOD;}
}
import();
var_dump(namespace::HI);
namespace::list();
?>and results in this output:
cellog@lot-49:~/workspace/php5$ sapi/cli/php -n testme.php
import functionint(3)
import::namespace::listI have not performed profiling on the patch, instead focusing on
correctness for now.The patch looks complicated because of the additional states, but is
really not that complicated, honest.:)
Greg? Zend/tests/zend_function_name.phpt
Index: Zend/zend_compile.cRCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.647.2.27.2.41.2.10
diff -u -r1.647.2.27.2.41.2.10 zend_compile.c
--- Zend/zend_compile.c 17 Oct 2007 10:01:21 -0000 1.647.2.27.2.41.2.10
+++ Zend/zend_compile.c 23 Oct 2007 03:15:41 -0000
@@ -2975,7 +2975,7 @@lcname = zend_str_tolower_dup(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len);
if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
if (!(strcmp(lcname, "self") && strcmp(lcname, "parent") && strcmp(lcname, "static"))) { efree(lcname); zend_error(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved", class_name->u.constant.value.str.val); }
@@ -4582,7 +4582,9 @@
if (((Z_STRLEN(name->u.constant) == sizeof("self")-1) &&
!memcmp(lcname, "self", sizeof("self")-1)) ||
((Z_STRLEN(name->u.constant) == sizeof("parent")-1) &&
!memcmp(lcname, "parent", sizeof("parent")-1))) {
!memcmp(lcname, "parent", sizeof("parent")-1)) ||
((Z_STRLEN(name->u.constant) == sizeof("static")-1) &&
!memcmp(lcname, "static", sizeof("static")-1))) { zend_error(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", Z_STRVAL(name->u.constant)); } efree(lcname);
@@ -4596,7 +4598,7 @@
{
char *lcname;
zval *name, *ns, tmp;
zend_bool warn = 0;
zend_bool warn = 0, shorthand = 0; if (!CG(current_import)) { CG(current_import) = emalloc(sizeof(HashTable));
@@ -4611,11 +4613,12 @@
char *p;/* The form "import A::B" is eqivalent to "import A::B as B".
So we extract the last part of compound name ti use as a new_name */
So we extract the last part of compound name to use as a new_name */ name = &tmp; p = zend_memrchr(Z_STRVAL_P(ns), ':', Z_STRLEN_P(ns)); if (p) { ZVAL_STRING(name, p+1, 1);
shorthand = 1; } else { *name = *ns; zval_copy_ctor(name);
@@ -4627,6 +4630,8 @@
if (((Z_STRLEN_P(name) == sizeof("self")-1) && !memcmp(lcname, "self", sizeof("self")-1)) ||
((Z_STRLEN_P(name) == sizeof("static")-1) &&
!memcmp(lcname, "static", sizeof("static")-1)) || ((Z_STRLEN_P(name) == sizeof("parent")-1) && !memcmp(lcname, "parent", sizeof("parent")-1))) { zend_error(E_COMPILE_ERROR, "Cannot use '%s' as import name", Z_STRVAL_P(name));
@@ -4640,7 +4645,8 @@
ns_name[Z_STRLEN_P(CG(current_namespace))] = ':';
ns_name[Z_STRLEN_P(CG(current_namespace))+1] = ':';
memcpy(ns_name+Z_STRLEN_P(CG(current_namespace))+2, lcname, Z_STRLEN_P(name)+1);
if (zend_hash_exists(CG(class_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) {
/* if our new import name is simply the shorthand, skip this check */
if ((!shorthand || !memcmp(ns_name, Z_STRVAL_P(ns), Z_STRLEN_P(ns) + 1)) && zend_hash_exists(CG(class_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) { zend_error(E_COMPILE_ERROR, "Import name '%s' conflicts with defined class", Z_STRVAL_P(name)); } efree(ns_name);
Index: Zend/zend_language_parser.y
RCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.8.2.4
diff -u -r1.160.2.4.2.8.2.4 zend_language_parser.y
--- Zend/zend_language_parser.y 1 Oct 2007 10:37:13 -0000 1.160.2.4.2.8.2.4
+++ Zend/zend_language_parser.y 23 Oct 2007 03:15:41 -0000
@@ -47,7 +47,7 @@
%}%pure_parser
-%expect 2
+%expect 3%left
T_INCLUDE
T_INCLUDE_ONCET_EVAL
T_REQUIRET_REQUIRE_ONCE
%left ','
@@ -142,7 +142,7 @@
%tokenT_END_HEREDOC
%tokenT_DOLLAR_OPEN_CURLY_BRACES
%tokenT_CURLY_OPEN
-%tokenT_PAAMAYIM_NEKUDOTAYIM
+%leftT_PAAMAYIM_NEKUDOTAYIM
%tokenT_NAMESPACE
%token T_IMPORT
%tokenT_NS_C
@@ -160,6 +160,8 @@namespace_name:
T_STRING
{ $$ = $1; }
| T_IMPORT { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; } | namespace_name `T_PAAMAYIM_NEKUDOTAYIM` T_STRING { zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
;
@@ -168,9 +170,9 @@
| function_declaration_statement { zend_do_early_binding(TSRMLS_C); }
| class_declaration_statement { zend_do_early_binding(TSRMLS_C); }
|T_HALT_COMPILER
'(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; }
| `T_NAMESPACE` namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
| T_IMPORT namespace_name ';' { zend_do_import(&$2, `NULL` TSRMLS_CC); }
| T_IMPORT namespace_name `T_AS` T_STRING ';' { zend_do_import(&$2, &$4 TSRMLS_CC); }
| `T_NAMESPACE` namespace_name ';' { efree($1.u.constant.value.str.val);zend_do_namespace(&$2 TSRMLS_CC); }
| T_IMPORT fully_qualified_class_name ';' { efree($1.u.constant.value.str.val);zend_do_import(&$2, `NULL` TSRMLS_CC); }
| T_IMPORT fully_qualified_class_name `T_AS` function_name_token ';' { efree($1.u.constant.value.str.val);zend_do_import(&$2, &$4 TSRMLS_CC); } | constant_declaration ';'
;
@@ -298,6 +300,12 @@
'(' parameter_list ')' '{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); }
;+function_name_token:
`T_STRING` { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; }
| T_IMPORT { $$ = $1; }
+;
unticked_class_declaration_statement:
class_entry_typeT_STRING
extends_from
{ zend_do_begin_class_declaration(&$1, &$2, &$3 TSRMLS_CC); }
@@ -636,7 +644,7 @@
;function_call:
`T_STRING` '(' { $2.u.opline_num = zend_do_begin_function_call(&$1, 1 TSRMLS_CC); }
function_name_token '(' { $2.u.opline_num = zend_do_begin_function_call(&$1, 1 TSRMLS_CC); } function_call_parameter_list ')' { zend_do_end_function_call(&$1, &$$, &$4, 0, $2.u.opline_num TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C); } | `T_PAAMAYIM_NEKUDOTAYIM` T_STRING '(' { $3.u.opline_num = zend_do_begin_function_call(&$2, 0 TSRMLS_CC); }
@@ -661,6 +669,8 @@
fully_qualified_class_name:
T_STRING
{ $$ = $1; }
| T_IMPORT { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; } | `T_STATIC` { $$.op_type = IS_CONST; ZVAL_STRINGL(&$$.u.constant, "static", sizeof("static")-1, 1);} | `T_PAAMAYIM_NEKUDOTAYIM` T_STRING { zend_do_build_namespace_name(&$$, NULL, &$2 TSRMLS_CC); } | fully_qualified_class_name `T_PAAMAYIM_NEKUDOTAYIM` T_STRING { zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
Index: Zend/zend_language_scanner.l
RCS file: /repository/ZendEngine2/zend_language_scanner.l,v
retrieving revision 1.131.2.11.2.13.2.2
diff -u -r1.131.2.11.2.13.2.2 zend_language_scanner.l
--- Zend/zend_language_scanner.l 7 Oct 2007 05:22:03 -0000 1.131.2.11.2.13.2.2
+++ Zend/zend_language_scanner.l 23 Oct 2007 03:15:42 -0000
@@ -45,6 +45,11 @@
%x ST_COMMENT
%x ST_DOC_COMMENT
%x ST_ONE_LINE_COMMENT
+%x ST_LOOKING_FOR_CLASSNAME
+%x ST_LOOKING_FOR_EXTENDS
+%x ST_LOOKING_FOR_IMPLEMENTS
+%x ST_LOOKING_FOR_FUNCTION_NAME
+%x ST_LOOKING_FOR_METHOD_NAME
%option stack%{
@@ -969,143 +974,172 @@
%option noyywrap
%%-<ST_IN_SCRIPTING>"exit" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"exit" {
return T_EXIT;
}-<ST_IN_SCRIPTING>"die" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"die" {
return T_EXIT;
}<ST_IN_SCRIPTING>"function" {
if (CG(active_class_entry)) {
yy_push_state(ST_LOOKING_FOR_METHOD_NAME TSRMLS_CC);
} else {
yy_push_state(ST_LOOKING_FOR_FUNCTION_NAME TSRMLS_CC);
}
return T_FUNCTION;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"function" {
return T_FUNCTION;
}-<ST_IN_SCRIPTING>"const" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"const" {
return T_CONST;
}-<ST_IN_SCRIPTING>"return" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"return" {
return T_RETURN;
}-<ST_IN_SCRIPTING>"try" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"try" {
return T_TRY;
}-<ST_IN_SCRIPTING>"catch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"catch" {
return T_CATCH;
}-<ST_IN_SCRIPTING>"throw" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"throw" {
return T_THROW;
}-<ST_IN_SCRIPTING>"if" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"if" {
return T_IF;
}-<ST_IN_SCRIPTING>"elseif" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"elseif" {
return T_ELSEIF;
}-<ST_IN_SCRIPTING>"endif" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endif" {
return T_ENDIF;
}-<ST_IN_SCRIPTING>"else" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"else" {
return T_ELSE;
}-<ST_IN_SCRIPTING>"while" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"while" {
return T_WHILE;
}-<ST_IN_SCRIPTING>"endwhile" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endwhile" {
return T_ENDWHILE;
}-<ST_IN_SCRIPTING>"do" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"do" {
return T_DO;
}-<ST_IN_SCRIPTING>"for" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"for" {
return T_FOR;
}-<ST_IN_SCRIPTING>"endfor" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endfor" {
return T_ENDFOR;
}-<ST_IN_SCRIPTING>"foreach" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"foreach" {
return T_FOREACH;
}-<ST_IN_SCRIPTING>"endforeach" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endforeach" {
return T_ENDFOREACH;
}-<ST_IN_SCRIPTING>"declare" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"declare" {
return T_DECLARE;
}-<ST_IN_SCRIPTING>"enddeclare" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"enddeclare" {
return T_ENDDECLARE;
}-<ST_IN_SCRIPTING>"instanceof" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"instanceof" {
return T_INSTANCEOF;
}-<ST_IN_SCRIPTING>"as" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"as" {
return T_AS;
}-<ST_IN_SCRIPTING>"switch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"switch" {
return T_SWITCH;
}-<ST_IN_SCRIPTING>"endswitch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endswitch" {
return T_ENDSWITCH;
}-<ST_IN_SCRIPTING>"case" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"case" {
return T_CASE;
}-<ST_IN_SCRIPTING>"default" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"default" {
return T_DEFAULT;
}-<ST_IN_SCRIPTING>"break" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"break" {
return T_BREAK;
}-<ST_IN_SCRIPTING>"continue" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"continue" {
return T_CONTINUE;
}-<ST_IN_SCRIPTING>"echo" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"echo" {
return T_ECHO;
}-<ST_IN_SCRIPTING>"print" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"print" {
return T_PRINT;
}<ST_IN_SCRIPTING>"class" {
yy_push_state(ST_LOOKING_FOR_CLASSNAME TSRMLS_CC);
return T_CLASS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"class" {
return T_CLASS;
}<ST_IN_SCRIPTING>"interface" {
yy_push_state(ST_LOOKING_FOR_CLASSNAME TSRMLS_CC);
return T_INTERFACE;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"interface" {
return T_INTERFACE;
}<ST_IN_SCRIPTING>"extends" {
yy_push_state(ST_LOOKING_FOR_EXTENDS TSRMLS_CC);
return T_EXTENDS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"extends" {
return T_EXTENDS;
}<ST_IN_SCRIPTING>"implements" {
yy_push_state(ST_LOOKING_FOR_IMPLEMENTS TSRMLS_CC);
return T_IMPLEMENTS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"implements" {
return T_IMPLEMENTS;
}@@ -1118,31 +1152,47 @@
return T_OBJECT_OPERATOR;
}-<ST_LOOKING_FOR_PROPERTY>{LABEL} {
+<ST_LOOKING_FOR_METHOD_NAME>'&' {
return '&';
+}
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
HANDLE_NEWLINES(yytext, yyleng);
return T_WHITESPACE;
+}
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{LABEL} {
yy_pop_state(TSRMLS_C);
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING;
return T_STRING;
}-<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{ANY_CHAR} {
yyless(0);
yy_pop_state(TSRMLS_C);
}<ST_IN_SCRIPTING>"::" {
yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC); return T_PAAMAYIM_NEKUDOTAYIM;
}
<ST_IN_SCRIPTING>"new" {
yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC); return T_NEW;
}
-<ST_IN_SCRIPTING>"clone" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"clone" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_CLONE;
}
-<ST_IN_SCRIPTING>"var" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"var" {
return T_VAR;
}@@ -1178,79 +1228,83 @@
return T_UNSET_CAST;
}-<ST_IN_SCRIPTING>"eval" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"eval" {
return T_EVAL;
}-<ST_IN_SCRIPTING>"include" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"include" {
return T_INCLUDE;
}-<ST_IN_SCRIPTING>"include_once" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"include_once" {
return T_INCLUDE_ONCE;
}-<ST_IN_SCRIPTING>"require" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"require" {
return T_REQUIRE;
}-<ST_IN_SCRIPTING>"require_once" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"require_once" {
return T_REQUIRE_ONCE;
}<ST_IN_SCRIPTING>"namespace" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_NAMESPACE;
}
<ST_IN_SCRIPTING>"import" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_IMPORT;
}
-<ST_IN_SCRIPTING>"use" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"use" {
return T_USE;
}-<ST_IN_SCRIPTING>"global" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"global" {
return T_GLOBAL;
}-<ST_IN_SCRIPTING>"isset" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"isset" {
return T_ISSET;
}-<ST_IN_SCRIPTING>"empty" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"empty" {
return T_EMPTY;
}-<ST_IN_SCRIPTING>"__halt_compiler" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"__halt_compiler" {
return T_HALT_COMPILER;
}-<ST_IN_SCRIPTING>"static" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"static" {
return T_STATIC;
}-<ST_IN_SCRIPTING>"abstract" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"abstract" {
return T_ABSTRACT;
}-<ST_IN_SCRIPTING>"final" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"final" {
return T_FINAL;
}-<ST_IN_SCRIPTING>"private" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"private" {
return T_PRIVATE;
}-<ST_IN_SCRIPTING>"protected" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"protected" {
return T_PROTECTED;
}-<ST_IN_SCRIPTING>"public" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"public" {
return T_PUBLIC;
}-<ST_IN_SCRIPTING>"unset" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"unset" {
return T_UNSET;
}@@ -1258,11 +1312,11 @@
return T_DOUBLE_ARROW;
}-<ST_IN_SCRIPTING>"list" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"list" {
return T_LIST;
}-<ST_IN_SCRIPTING>"array" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"array" {
return T_ARRAY;
}@@ -1480,7 +1534,7 @@
return T_DNUMBER;
}-<ST_IN_SCRIPTING>"CLASS" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"CLASS" {
char *class_name = NULL;if (CG(active_class_entry)) {
@@ -1496,7 +1550,7 @@
return T_CLASS_C;
}-<ST_IN_SCRIPTING>"FUNCTION" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"FUNCTION" {
char *func_name = NULL;if (CG(active_op_array)) {
@@ -1512,7 +1566,7 @@
return T_FUNC_C;
}-<ST_IN_SCRIPTING>"METHOD" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"METHOD" {
char *class_name = CG(active_class_entry) ? CG(active_class_entry)->name : NULL;
char *func_name = CG(active_op_array)? CG(active_op_array)->function_name : NULL;
size_t len = 0;
@@ -1533,13 +1587,13 @@
return T_METHOD_C;
}-<ST_IN_SCRIPTING>"LINE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"LINE" {
zendlval->value.lval = CG(zend_lineno);
zendlval->type = IS_LONG;
return T_LINE;
}-<ST_IN_SCRIPTING>"FILE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"FILE" {
char *filename = zend_get_compiled_filename(TSRMLS_C);if (!filename) {
@@ -1551,7 +1605,7 @@
return T_FILE;
}-<ST_IN_SCRIPTING>"NAMESPACE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"NAMESPACE" {
if (CG(current_namespace)) {
*zendlval = *CG(current_namespace);
zval_copy_ctor(zendlval);
@@ -1561,6 +1615,38 @@
return T_NS_C;
}+<ST_LOOKING_FOR_IMPLEMENTS>"," {
return ',';
+}
+<ST_LOOKING_FOR_FUNCTION_NAME>"&" {
return '&';
+}
+<ST_LOOKING_FOR_IMPLEMENTS>"::" {
return T_PAAMAYIM_NEKUDOTAYIM;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
HANDLE_NEWLINES(yytext, yyleng);
return T_WHITESPACE;
+}
+<ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME,ST_LOOKING_FOR_IMPLEMENTS>{LABEL} {
yy_pop_state(TSRMLS_C);
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING;
return T_STRING;
+}
+<ST_LOOKING_FOR_FUNCTION_NAME,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_IMPLEMENTS>{ANY_CHAR} {
yyless(0);
yy_pop_state(TSRMLS_C);
+}
<INITIAL>(([^<]|"<"[^?%s<]){1,400})|"<s"|"<" {
#ifdef ZEND_MULTIBYTE
if (SCNG(output_filter)) {
@@ -1693,7 +1779,6 @@
return T_STRING;
}
<ST_IN_SCRIPTING>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying - intentional */
zendlval->value.str.len = yyleng;--
--
Pagarbiai
Giedrius Dubinskas
Mob.: 8 672 42863
yeah. let's just go for "use".
David
Am 23.10.2007 um 11:08 schrieb Giedrius D:
Hi,
sorry if I missed something but is there any reason to not use
keyword "use"?IMHO allowing keywords in class, method, function, etc. names brings
more confusion then value.Stanislav Malyshev wrote:
Hold off for a bit - I may have a simple solution that solves the
problem for class names, method names and functions, have to
code the
patch tonight first to prove it works.OK, please send it as soon as you have it :)
Hi,The attached patch is for PHP 5.3, if it is acceptable, I will
port it
to PHP 6, which is not difficult, although it does involve a lot of
cut/pasting.The patch does these things:
- fixes an unrelated bug I found in implementation of LSB -
"static" is
not checked for in zend_do_import()/zend_do_namespace() and other
places
that we check for "self" and "parent"- fixes a rather serious error in the fix for Bug #42859 - missing
parens in zend_do_import()- adds "import" and "namespace" as valid function/class names
- allows any string for method names, just as we allow any string
for
variable names- fixes a bug in logic for $class->list where $class-> list (note
the
whitespace between -> and list) returns aT_LIST
instead ofT_STRING
- It allows "import ::Classname as Blah" which is currently a
parse error- class constants are unchanged - reserved words still error out.
Note that the zend_compile.c fixes can all be committed directly
as they
are all bugfixes and not related to the import/namespace/reserved
words fix.To implement this, I added several states to the lexer in order to
returnT_STRING
whenever possible, which is after T_NEW, T_INTERFACE,
T_CLASS,T_EXTENDS
and in theT_IMPLEMENTS
list. In addition, after
T_FUNCTION
outside of a class, it returnsT_STRING
for "import" and
"namespace" but no other reserved words. AfterT_FUNCTION
inside
of a
class (method declaration), it returnsT_STRING
for all possible
strings. After :: or ->T_STRING
is always returned. Also,
rather than
take the approach LSB does with T_STATIC, I have the lexer initialize
the string value of T_IMPORT andT_NAMESPACE
so we can preserve
case for
autoloading needs. The parser frees the unused char * when normal
import/namespace declarations are called.In the parser, I use fully_qualified_class_name instead of
namespace_name for both import syntaxes. This introduces a minor
issue
in that this is no longer a parse error:import static::oops as Classname;
However, if "Classname" is used, this will simply result in "Fatal
error: Class 'static::oops' not found in..." and shouldn't be too
big of
a deal. Also in the parser, I inserted T_IMPORT andT_NAMESPACE
as
aliases toT_STRING
in global situations to allow for static method
calls, class constants, and fully-qualified namespace calls.Basically this script is now possible with the patch:
<?php
namespace import;
import ::Exception as Test;
function import() {echo 'import function';}
interface import {}
interface fooey {}
class Exception extends ::Exception implements fooey, import {}
class namespace {
const HI = 3;
function list() {echo METHOD;}
}
import();
var_dump(namespace::HI);
namespace::list();
?>and results in this output:
cellog@lot-49:~/workspace/php5$ sapi/cli/php -n testme.php
import functionint(3)
import::namespace::listI have not performed profiling on the patch, instead focusing on
correctness for now.The patch looks complicated because of the additional states, but is
really not that complicated, honest.:)
Greg? Zend/tests/zend_function_name.phpt
Index: Zend/zend_compile.cRCS file: /repository/ZendEngine2/zend_compile.c,v
retrieving revision 1.647.2.27.2.41.2.10
diff -u -r1.647.2.27.2.41.2.10 zend_compile.c
--- Zend/zend_compile.c 17 Oct 2007 10:01:21 -0000
1.647.2.27.2.41.2.10
+++ Zend/zend_compile.c 23 Oct 2007 03:15:41 -0000
@@ -2975,7 +2975,7 @@lcname = zend_str_tolower_dup(class_name-
u.constant.value.str.val, class_name->u.constant.value.str.len);
if (!(strcmp(lcname, "self") && strcmp(lcname, "parent"))) {
if (!(strcmp(lcname, "self") && strcmp(lcname, "parent")
&& strcmp(lcname, "static"))) {
efree(lcname);
zend_error(E_COMPILE_ERROR, "Cannot use '%s' as
class name as it is reserved", class_name->u.constant.value.str.val);
}
@@ -4582,7 +4582,9 @@
if (((Z_STRLEN(name->u.constant) == sizeof("self")-1) &&
!memcmp(lcname, "self", sizeof("self")-1)) ||
((Z_STRLEN(name->u.constant) == sizeof("parent")-1) &&
!memcmp(lcname, "parent", sizeof("parent")-1))) {
!memcmp(lcname, "parent", sizeof("parent")-1)) ||
((Z_STRLEN(name->u.constant) == sizeof("static")-1) &&
!memcmp(lcname, "static", sizeof("static")-1))) { zend_error(E_COMPILE_ERROR, "Cannot use '%s' as
namespace name", Z_STRVAL(name->u.constant));
}
efree(lcname);
@@ -4596,7 +4598,7 @@
{
char *lcname;
zval *name, *ns, tmp;
zend_bool warn = 0;
zend_bool warn = 0, shorthand = 0; if (!CG(current_import)) { CG(current_import) = emalloc(sizeof(HashTable));
@@ -4611,11 +4613,12 @@
char *p;/* The form "import A::B" is eqivalent to "import
A::B as B".
So we extract the last part of compound name ti
use as a new_name */
So we extract the last part of compound name to
use as a new_name */
name = &tmp;
p = zend_memrchr(Z_STRVAL_P(ns), ':', Z_STRLEN_P
(ns));
if (p) {
ZVAL_STRING(name, p+1, 1);
shorthand = 1; } else { *name = *ns; zval_copy_ctor(name);
@@ -4627,6 +4630,8 @@
if (((Z_STRLEN_P(name) == sizeof("self")-1) && !memcmp(lcname, "self", sizeof("self")-1)) ||
((Z_STRLEN_P(name) == sizeof("static")-1) &&
!memcmp(lcname, "static", sizeof("static")-1)) || ((Z_STRLEN_P(name) == sizeof("parent")-1) && !memcmp(lcname, "parent", sizeof("parent")-1))) { zend_error(E_COMPILE_ERROR, "Cannot use '%s' as
import name", Z_STRVAL_P(name));
@@ -4640,7 +4645,8 @@
ns_name[Z_STRLEN_P(CG(current_namespace))] = ':';
ns_name[Z_STRLEN_P(CG(current_namespace))+1] = ':';
memcpy(ns_name+Z_STRLEN_P(CG(current_namespace))
+2, lcname, Z_STRLEN_P(name)+1);
if (zend_hash_exists(CG(class_table), ns_name,
Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) {
/* if our new import name is simply the shorthand,
skip this check */
if ((!shorthand || !memcmp(ns_name, Z_STRVAL_P
(ns), Z_STRLEN_P(ns) + 1)) && zend_hash_exists(CG(class_table),
ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)
+1)) {
zend_error(E_COMPILE_ERROR, "Import name '%
s' conflicts with defined class", Z_STRVAL_P(name));
}
efree(ns_name);
Index: Zend/zend_language_parser.yRCS file: /repository/ZendEngine2/zend_language_parser.y,v
retrieving revision 1.160.2.4.2.8.2.4
diff -u -r1.160.2.4.2.8.2.4 zend_language_parser.y
--- Zend/zend_language_parser.y 1 Oct 2007 10:37:13 -0000
1.160.2.4.2.8.2.4
+++ Zend/zend_language_parser.y 23 Oct 2007 03:15:41 -0000
@@ -47,7 +47,7 @@
%}%pure_parser
-%expect 2
+%expect 3%left
T_INCLUDE
T_INCLUDE_ONCET_EVAL
T_REQUIRET_REQUIRE_ONCE
%left ','
@@ -142,7 +142,7 @@
%tokenT_END_HEREDOC
%tokenT_DOLLAR_OPEN_CURLY_BRACES
%tokenT_CURLY_OPEN
-%tokenT_PAAMAYIM_NEKUDOTAYIM
+%leftT_PAAMAYIM_NEKUDOTAYIM
%tokenT_NAMESPACE
%token T_IMPORT
%tokenT_NS_C
@@ -160,6 +160,8 @@namespace_name:
T_STRING
{ $$ = $1; }
| T_IMPORT { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; } | namespace_name `T_PAAMAYIM_NEKUDOTAYIM` T_STRING
{ zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
;@@ -168,9 +170,9 @@
| function_declaration_statement
{ zend_do_early_binding(TSRMLS_C); }
| class_declaration_statement
{ zend_do_early_binding(TSRMLS_C); }
|T_HALT_COMPILER
'(' ')'
';' { zend_do_halt_compiler_register(TSRMLS_C);
YYACCEPT; }
| `T_NAMESPACE` namespace_name ';' { zend_do_namespace
(&$2 TSRMLS_CC); }
| T_IMPORT namespace_name
';' { zend_do_import(&$2,
NULL
TSRMLS_CC); }
| T_IMPORT namespace_name `T_AS` T_STRING
';' { zend_do_import(&$2, &$4 TSRMLS_CC); }
| `T_NAMESPACE` namespace_name ';' { efree
($1.u.constant.value.str.val);zend_do_namespace(&$2 TSRMLS_CC); }
| T_IMPORT fully_qualified_class_name
';' { efree($1.u.constant.value.str.val);zend_do_import(&
$2,NULL
TSRMLS_CC); }
| T_IMPORT fully_qualified_class_name `T_AS`
function_name_token ';' { efree
($1.u.constant.value.str.val);zend_do_import(&$2, &$4 TSRMLS_CC); }
| constant_declaration ';'
;@@ -298,6 +300,12 @@
'(' parameter_list ')' '{'
inner_statement_list '}' { zend_do_end_function_declaration(&$1
TSRMLS_CC); }
;+function_name_token:
`T_STRING` { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; }
| T_IMPORT { $$ = $1; }
+;
unticked_class_declaration_statement:
class_entry_typeT_STRING
extends_from
{ zend_do_begin_class_declaration(&$1, &
$2, &$3 TSRMLS_CC); }
@@ -636,7 +644,7 @@
;function_call:
`T_STRING` '(' { $2.u.opline_num =
zend_do_begin_function_call(&$1, 1 TSRMLS_CC); }
function_name_token '(' { $2.u.opline_num =
zend_do_begin_function_call(&$1, 1 TSRMLS_CC); }
function_call_parameter_list
')' { zend_do_end_function_call(&
$1, &$$, &$4, 0, $2.u.opline_num TSRMLS_CC);
zend_do_extended_fcall_end(TSRMLS_C); }
|T_PAAMAYIM_NEKUDOTAYIM
T_STRING
'(' { $3.u.opline_num = zend_do_begin_function_call(&$2, 0
TSRMLS_CC); }
@@ -661,6 +669,8 @@fully_qualified_class_name:
T_STRING
{ $$ = $1; }
| T_IMPORT { $$ = $1; }
| `T_NAMESPACE` { $$ = $1; } | `T_STATIC` { $$.op_type = IS_CONST; ZVAL_STRINGL(&$
$.u.constant, "static", sizeof("static")-1, 1);}
|T_PAAMAYIM_NEKUDOTAYIM
T_STRING
{ zend_do_build_namespace_name(&$$, NULL, &$2 TSRMLS_CC); }
| fully_qualified_class_nameT_PAAMAYIM_NEKUDOTAYIM
T_STRING
{ zend_do_build_namespace_name(&$$, &$1, &$3 TSRMLS_CC); }
Index: Zend/zend_language_scanner.lRCS file: /repository/ZendEngine2/zend_language_scanner.l,v
retrieving revision 1.131.2.11.2.13.2.2
diff -u -r1.131.2.11.2.13.2.2 zend_language_scanner.l
--- Zend/zend_language_scanner.l 7 Oct 2007 05:22:03
-0000 1.131.2.11.2.13.2.2
+++ Zend/zend_language_scanner.l 23 Oct 2007 03:15:42 -0000
@@ -45,6 +45,11 @@
%x ST_COMMENT
%x ST_DOC_COMMENT
%x ST_ONE_LINE_COMMENT
+%x ST_LOOKING_FOR_CLASSNAME
+%x ST_LOOKING_FOR_EXTENDS
+%x ST_LOOKING_FOR_IMPLEMENTS
+%x ST_LOOKING_FOR_FUNCTION_NAME
+%x ST_LOOKING_FOR_METHOD_NAME
%option stack%{
@@ -969,143 +974,172 @@
%option noyywrap
%%-<ST_IN_SCRIPTING>"exit" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"exit" {
return T_EXIT;
}-<ST_IN_SCRIPTING>"die" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"die" {
return T_EXIT;
}<ST_IN_SCRIPTING>"function" {
if (CG(active_class_entry)) {
yy_push_state(ST_LOOKING_FOR_METHOD_NAME TSRMLS_CC);
} else {
yy_push_state(ST_LOOKING_FOR_FUNCTION_NAME
TSRMLS_CC);
}
return T_FUNCTION;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"function" {
return T_FUNCTION;
}-<ST_IN_SCRIPTING>"const" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"const" {
return T_CONST;
}-<ST_IN_SCRIPTING>"return" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"return" {
return T_RETURN;
}-<ST_IN_SCRIPTING>"try" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"try" {
return T_TRY;
}-<ST_IN_SCRIPTING>"catch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"catch" {
return T_CATCH;
}-<ST_IN_SCRIPTING>"throw" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"throw" {
return T_THROW;
}-<ST_IN_SCRIPTING>"if" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"if" {
return T_IF;
}-<ST_IN_SCRIPTING>"elseif" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"elseif" {
return T_ELSEIF;
}-<ST_IN_SCRIPTING>"endif" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endif" {
return T_ENDIF;
}-<ST_IN_SCRIPTING>"else" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"else" {
return T_ELSE;
}-<ST_IN_SCRIPTING>"while" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"while" {
return T_WHILE;
}-<ST_IN_SCRIPTING>"endwhile" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endwhile" {
return T_ENDWHILE;
}-<ST_IN_SCRIPTING>"do" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"do" {
return T_DO;
}-<ST_IN_SCRIPTING>"for" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"for" {
return T_FOR;
}-<ST_IN_SCRIPTING>"endfor" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endfor" {
return T_ENDFOR;
}-<ST_IN_SCRIPTING>"foreach" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"foreach" {
return T_FOREACH;
}-<ST_IN_SCRIPTING>"endforeach" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endforeach" {
return T_ENDFOREACH;
}-<ST_IN_SCRIPTING>"declare" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"declare" {
return T_DECLARE;
}-<ST_IN_SCRIPTING>"enddeclare" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"enddeclare" {
return T_ENDDECLARE;
}-<ST_IN_SCRIPTING>"instanceof" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"instanceof" {
return T_INSTANCEOF;
}-<ST_IN_SCRIPTING>"as" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"as" {
return T_AS;
}-<ST_IN_SCRIPTING>"switch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"switch" {
return T_SWITCH;
}-<ST_IN_SCRIPTING>"endswitch" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"endswitch" {
return T_ENDSWITCH;
}-<ST_IN_SCRIPTING>"case" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"case" {
return T_CASE;
}-<ST_IN_SCRIPTING>"default" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"default" {
return T_DEFAULT;
}-<ST_IN_SCRIPTING>"break" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"break" {
return T_BREAK;
}-<ST_IN_SCRIPTING>"continue" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"continue" {
return T_CONTINUE;
}-<ST_IN_SCRIPTING>"echo" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"echo" {
return T_ECHO;
}-<ST_IN_SCRIPTING>"print" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"print" {
return T_PRINT;
}<ST_IN_SCRIPTING>"class" {
yy_push_state(ST_LOOKING_FOR_CLASSNAME TSRMLS_CC);
return T_CLASS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"class" {
return T_CLASS;
}<ST_IN_SCRIPTING>"interface" {
yy_push_state(ST_LOOKING_FOR_CLASSNAME TSRMLS_CC);
return T_INTERFACE;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"interface" {
return T_INTERFACE;
}<ST_IN_SCRIPTING>"extends" {
yy_push_state(ST_LOOKING_FOR_EXTENDS TSRMLS_CC);
return T_EXTENDS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"extends" {
return T_EXTENDS;
}<ST_IN_SCRIPTING>"implements" {
yy_push_state(ST_LOOKING_FOR_IMPLEMENTS TSRMLS_CC);
return T_IMPLEMENTS;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"implements" {
return T_IMPLEMENTS;
}@@ -1118,31 +1152,47 @@
return T_OBJECT_OPERATOR;
}-<ST_LOOKING_FOR_PROPERTY>{LABEL} {
+<ST_LOOKING_FOR_METHOD_NAME>'&' {
return '&';
+}
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying -
intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
HANDLE_NEWLINES(yytext, yyleng);
return T_WHITESPACE;
+}
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{LABEL} {
yy_pop_state(TSRMLS_C);
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING;
return T_STRING;
}-<ST_LOOKING_FOR_PROPERTY>{ANY_CHAR} {
+<ST_LOOKING_FOR_PROPERTY,ST_LOOKING_FOR_METHOD_NAME>{ANY_CHAR} {
yyless(0);
yy_pop_state(TSRMLS_C);
}<ST_IN_SCRIPTING>"::" {
yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC); return T_PAAMAYIM_NEKUDOTAYIM;
}
<ST_IN_SCRIPTING>"new" {
yy_push_state(ST_LOOKING_FOR_PROPERTY TSRMLS_CC); return T_NEW;
}
-<ST_IN_SCRIPTING>"clone" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"clone" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_CLONE;
}
-<ST_IN_SCRIPTING>"var" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"var" {
return T_VAR;
}@@ -1178,79 +1228,83 @@
return T_UNSET_CAST;
}-<ST_IN_SCRIPTING>"eval" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"eval" {
return T_EVAL;
}-<ST_IN_SCRIPTING>"include" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"include" {
return T_INCLUDE;
}-<ST_IN_SCRIPTING>"include_once" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"include_once" {
return T_INCLUDE_ONCE;
}-<ST_IN_SCRIPTING>"require" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"require" {
return T_REQUIRE;
}-<ST_IN_SCRIPTING>"require_once" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"require_once" {
return T_REQUIRE_ONCE;
}<ST_IN_SCRIPTING>"namespace" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_NAMESPACE;
}
<ST_IN_SCRIPTING>"import" {
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING; return T_IMPORT;
}
-<ST_IN_SCRIPTING>"use" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"use" {
return T_USE;
}-<ST_IN_SCRIPTING>"global" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"global" {
return T_GLOBAL;
}-<ST_IN_SCRIPTING>"isset" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"isset" {
return T_ISSET;
}-<ST_IN_SCRIPTING>"empty" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"empty" {
return T_EMPTY;
}-<ST_IN_SCRIPTING>"__halt_compiler" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"__halt_compiler"
{
return T_HALT_COMPILER;
}-<ST_IN_SCRIPTING>"static" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"static" {
return T_STATIC;
}-<ST_IN_SCRIPTING>"abstract" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"abstract" {
return T_ABSTRACT;
}-<ST_IN_SCRIPTING>"final" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"final" {
return T_FINAL;
}-<ST_IN_SCRIPTING>"private" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"private" {
return T_PRIVATE;
}-<ST_IN_SCRIPTING>"protected" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"protected" {
return T_PROTECTED;
}-<ST_IN_SCRIPTING>"public" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"public" {
return T_PUBLIC;
}-<ST_IN_SCRIPTING>"unset" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"unset" {
return T_UNSET;
}@@ -1258,11 +1312,11 @@
return T_DOUBLE_ARROW;
}-<ST_IN_SCRIPTING>"list" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"list" {
return T_LIST;
}-<ST_IN_SCRIPTING>"array" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"array" {
return T_ARRAY;
}@@ -1480,7 +1534,7 @@
return T_DNUMBER;
}-<ST_IN_SCRIPTING>"CLASS" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"CLASS" {
char *class_name = NULL;if (CG(active_class_entry)) {
@@ -1496,7 +1550,7 @@
return T_CLASS_C;
}-<ST_IN_SCRIPTING>"FUNCTION" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"FUNCTION" {
char *func_name = NULL;if (CG(active_op_array)) {
@@ -1512,7 +1566,7 @@
return T_FUNC_C;
}-<ST_IN_SCRIPTING>"METHOD" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"METHOD" {
char *class_name = CG(active_class_entry) ? CG
(active_class_entry)->name : NULL;
char *func_name = CG(active_op_array)? CG(active_op_array)-function_name : NULL;
size_t len = 0;
@@ -1533,13 +1587,13 @@
return T_METHOD_C;
}-<ST_IN_SCRIPTING>"LINE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"LINE" {
zendlval->value.lval = CG(zend_lineno);
zendlval->type = IS_LONG;
return T_LINE;
}-<ST_IN_SCRIPTING>"FILE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"FILE" {
char *filename = zend_get_compiled_filename(TSRMLS_C);if (!filename) {
@@ -1551,7 +1605,7 @@
return T_FILE;
}-<ST_IN_SCRIPTING>"NAMESPACE" {
+<ST_IN_SCRIPTING,ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,
ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNCTION_NAME>"NAMESPACE" {
if (CG(current_namespace)) {
*zendlval = *CG(current_namespace);
zval_copy_ctor(zendlval);
@@ -1561,6 +1615,38 @@
return T_NS_C;
}+<ST_LOOKING_FOR_IMPLEMENTS>"," {
return ',';
+}
+<ST_LOOKING_FOR_FUNCTION_NAME>"&" {
return '&';
+}
+<ST_LOOKING_FOR_IMPLEMENTS>"::" {
return T_PAAMAYIM_NEKUDOTAYIM;
+}
+<ST_LOOKING_FOR_IMPLEMENTS,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_E
XTENDS,ST_LOOKING_FOR_FUNCTION_NAME>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying -
intentional */
zendlval->value.str.len = yyleng;
zendlval->type = IS_STRING;
HANDLE_NEWLINES(yytext, yyleng);
return T_WHITESPACE;
+}
+<ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FOR_EXTENDS,ST_LOOKING_FOR_FUNC
TION_NAME,ST_LOOKING_FOR_IMPLEMENTS>{LABEL} {
yy_pop_state(TSRMLS_C);
zend_copy_value(zendlval, yytext, yyleng);
zendlval->type = IS_STRING;
return T_STRING;
+}
+<ST_LOOKING_FOR_FUNCTION_NAME,ST_LOOKING_FOR_CLASSNAME,ST_LOOKING_FO
R_EXTENDS,ST_LOOKING_FOR_IMPLEMENTS>{ANY_CHAR} {
yyless(0);
yy_pop_state(TSRMLS_C);
+}
<INITIAL>(([^<]|"<"[^?%s<]){1,400})|"<s"|"<" {
#ifdef ZEND_MULTIBYTE
if (SCNG(output_filter)) {
@@ -1693,7 +1779,6 @@
return T_STRING;
}
<ST_IN_SCRIPTING>{WHITESPACE} {
zendlval->value.str.val = yytext; /* no copying -
intentional */
zendlval->value.str.len = yyleng;--
--
Pagarbiai
Giedrius Dubinskas
Mob.: 8 672 42863
Giedrius D wrote:
Hi,
sorry if I missed something but is there any reason to not use keyword "use"?
IMHO allowing keywords in class, method, function, etc. names brings
more confusion then value.
The same confusion that is brought about by allowing keywords as
variable names?
<?php
class Test
{
public $class;
}
$a = new Test;
$a->class = 1;
?>
Is this next example any more confusing?
<?php
class Test
{
function class(){}
}
$a = new Test;
$a->class();
?>
I think you're confused by what is proposed :).
Greg
The same confusion that is brought about by allowing keywords as
variable names?<?php
class Test
{
public $class;
}$a = new Test;
$a->class = 1;
?>Is this next example any more confusing?
<?php
class Test
{
function class(){}
}$a = new Test;
$a->class();
?>I think you're confused by what is proposed :).
Yes you are right about the methods but consider something like this:
<?php
namespace (Foo::Bar);
import(new new);
// etc.
?>
Looks kinda odd to me although it might have sense in some context.
Anyway my main question was: is there any reason not to use keyword "use"?
Giedrius
Giedrius D wrote:
The same confusion that is brought about by allowing keywords as
variable names?<?php
class Test
{
public $class;
}$a = new Test;
$a->class = 1;
?>Is this next example any more confusing?
<?php
class Test
{
function class(){}
}$a = new Test;
$a->class();
?>I think you're confused by what is proposed :).
Yes you are right about the methods but consider something like this:
<?php
namespace (Foo::Bar);
import(new new);
parse error - of all reserved words, only "namespace" and "import" are
allowed as class names in my patch
// etc.
?>
Looks kinda odd to me although it might have sense in some context.Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing. If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.
However, no matter what I definitely would like to see code written for
PHP 5.2 and earlier that uses "import" or "namespace" as class names or
functions continue to work in PHP 5.3. "namespace" is used commonly for
XML information (for obvious reasons), and import is a very common idea,
as already stated.
Greg
<?php
namespace (Foo::Bar);
import(new new);parse error - of all reserved words, only "namespace" and "import" are
allowed as class names in my patch
Sorry missed that. Somehow I thought this applies only to functions.
Anyway allowing some keywords as class/function names and other not
adds some inconsistency to the language IMHO.
// etc.
?>
Looks kinda odd to me although it might have sense in some context.Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing.
I guess it's the matter of background. To me "import" implies
autoloading where "use" doesn't.
If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.However, no matter what I definitely would like to see code written for
PHP 5.2 and earlier that uses "import" or "namespace" as class names or
functions continue to work in PHP 5.3. "namespace" is used commonly for
XML information (for obvious reasons), and import is a very common idea,
as already stated.
I appreciate work but as I said above I think it adds inconsistency
and I think its not very good idea. I deffinetely agree that code
written for PHP 5.2 should continue to work in PHP 5.3. However this
patch is only one of possible solutions and it's up to you guys which
way to go.
Just a thought: maybe we should be discussing
namespace/name_space/something instead of import/use :-)
Just my 2 cents.
Giedrius
Gregory Beaver wrote:
Giedrius D wrote:
Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing. If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.
If I directly compare "use" with "import", "import" sounds way more like
"get me that stuff somehow magically" than "use" does.
- Sebastian
Hello Sebastian,
erm you are not going to use the stuff then?
marcus
Wednesday, October 24, 2007, 8:11:50 AM, you wrote:
Gregory Beaver wrote:
Giedrius D wrote:
Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing. If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.
If I directly compare "use" with "import", "import" sounds way more like
"get me that stuff somehow magically" than "use" does.
- Sebastian
Best regards,
Marcus
Marcus Boerger wrote:
Hello Sebastian,
erm you are not going to use the stuff then?
Of course. I was just trying to explain what the plain words sound like.
marcus
Wednesday, October 24, 2007, 8:11:50 AM, you wrote:
Gregory Beaver wrote:
Giedrius D wrote:
Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing. If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.If I directly compare "use" with "import", "import" sounds way more like
"get me that stuff somehow magically" than "use" does.
- Sebastian
Marcus Boerger wrote:
Hello Sebastian,
erm you are not going to use the stuff then?
Of course. I was just trying to explain, what the plain words sound like
to me.
marcus
Wednesday, October 24, 2007, 8:11:50 AM, you wrote:
Gregory Beaver wrote:
Giedrius D wrote:
Anyway my main question was: is there any reason not to use keyword "use"?
The only reason for me is that "use" implies some kind of autoloading,
as I suggested in one of my other mails. This gets into parsing
semantics, something I'm not interested in doing. If the folks go with
"use" that is fine, but for me personally not the best solution, which
is why I put hours into making this patch.If I directly compare "use" with "import", "import" sounds way more like
"get me that stuff somehow magically" than "use" does.
- Sebastian
Stanislav Malyshev wrote:
Since many packages (wordpress, propel, horde, phing, etc.) use "import"
as either class or function name, and we couldn't find a good solution
to make it work with import keyword without going into all kinds of
troublesome hacks, so we are thinking about replacing 'import' keyword
with 'use' keyword, which is already reserved.
If 'use' is already reserved, it makes the most sense IMO.
--
Brian Moon
Senior Developer
http://dealnews.com/
It's good to be cheap =)
Hei!
Since many packages (wordpress, propel, horde, phing, etc.) use "import" as
either class or function name, and we couldn't find a good solution to make it
work with import keyword without going into all kinds of troublesome hacks, so
we are thinking about replacing 'import' keyword with 'use' keyword, which is
already reserved.
Is there any progress on this? It's also breaking code like:
const IMPORT = 3;
regards,
Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org