Jump to content

bug in php language

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
paolodinhqd

paolodinhqd

    Newbie

  • Members
  • Pip
  • 5 posts
php seems to have a language bug, or better called "bad convention", :thumbdown:
you can't make a method named "new" :closedeyes:

you may try this:


class abc {

     function new() {

          echo "abc";

     }

}


any idea about this? :confused:

#2
brutetal

brutetal

    Newbie

  • Members
  • Pip
  • 6 posts
Thats because new is a keyword or modifier.
You can't use that as a name for a function.

So its not a bug.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
new is already a keyword in the language. You can't reuse it.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
paolodinhqd

paolodinhqd

    Newbie

  • Members
  • Pip
  • 5 posts
for me it's a real bug,
php is not like C, function name can be anything, there's no conflict if you choose a function name like "while", "for", "if", whatever....

It's the bad thinking of whom created php.
Another one, "empty" is also a php keyword, and you have class declaration as below:

class shopping_cart {
   function empty() {
  }
}

imagine about this case

#5
brutetal

brutetal

    Newbie

  • Members
  • Pip
  • 6 posts
PHP is based off of C. -.-;;

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
PHP is based off of ANSI C, and while often used is not a very code-complete language. You cannot define function names based off of such things.

PHP: The Basics - Manual


Your code:
[COLOR=#007700]class shopping_cart {
   function empty() {
   }
}[/COLOR]
Lets look at this example a little closer. Add the following lines before it:
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
And it shall state an obvious error. Your error reporting looks turned off, It'd be of help to turn it on!

#7
Jody LeCompte

Jody LeCompte

    Newbie

  • Members
  • PipPip
  • 18 posts
I don't have any experience with any form of C programming: If it allows you to use identifiers already present in the language such as if/while, how do you differentiate between the two when calling that function?

As for it being a bug or "poor thinking", scripting languages are generally much more forgiving syntax-wise than programming languages. Some things have to be sacrificed for that convenience. But if not being able to use common application terms such as empty or new really bothers you, you can always apply a single or double underscore before the function name.

#8
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts

paolodinhqd said:

for me it's a real bug,
php is not like C, function name can be anything, there's no conflict if you choose a function name like "while", "for", "if", whatever....

It's the bad thinking of whom created php.
Another one, "empty" is also a php keyword, and you have class declaration as below:

class shopping_cart {
   function empty() {
  }
}

imagine about this case

Almost every language has keywords that you cannot reuse. This is common, and part of learning to program is learning to respect that. It is not a language but, it's just inconvenient to you because you don't want to clarify what new thing you're doing.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#9
NastyDevil

NastyDevil

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
As Developers would say: it is by design. Meaning that even if it is a feature you do not agree with; it is intended to work in that manner.