Maybe a stupid question, but anyway...
Is there a way to call a class "New"?
Class New
{
..
}
Won't work of course, is there another way?
new is a reserved word in php. a class with name "new" is not valid php
http://www.php.net/manual/en/reserved.keywords.php
You cannot use (most of) PHPs keywords as identifier of classes, methods or functions. Just avoid them. However, New
is a really bad classname anyway, because its anything, but not self-speaking.
No, the word "new" is a reserved keyword (in probably all modern languages). You can't name anything "new". See the documentation for more detail: http://www.php.net/manual/en/reserved.keywords.php
You can declare a class "New"
, but it requires some stupid workarounds to actually use it:
class Old { /* ... */ }
class_alias("Old", "New");
$New = "new";
$n = new $New;
That's the only way to circumvent the reserved keyword issue. (New
and new
are the same in PHP, as it is case-insensitive for bare identifiers.)
精彩评论