PHP5 Object and Class Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • n8agrin@gmail.com

    #1

    PHP5 Object and Class Errors

    I've been doing some level of PHP programming for many years now, and
    have in the past few months started implementing lots of the core PHP5
    features into a new project, when I noticed some interesting issues
    with objects and classes.

    I'm having some problems with Object Oriented PHP5, namely when a class
    isn't defined correctly no errors are produced during object
    instantiation. For example if a method which violates a global
    namespace is defined inside a class I cannot get PHP to throw an error
    when that class is instantiated. PHP will catch simple errors such as
    lines not ending in semicolons, but doesn't catch these more 'global'
    issues.

    Worst of all, in my example where I violate the namespace, the program
    fatally dies and does so silently.

    If anyone else has experienced this issue, or if anyone knows how to
    get these types of errors to report themselves, it would be much
    appreciated.

    I'm sure this has been covered before and I just couldn't find the
    answer to my question on the board.

    Again, any help is much appreciated.

    Thanks,
    Nate

  • Oli Filth

    #2
    Re: PHP5 Object and Class Errors

    n8agrin@gmail.c om said the following on 09/04/2006 00:44:[color=blue]
    > I'm having some problems with Object Oriented PHP5, namely when a class
    > isn't defined correctly no errors are produced during object
    > instantiation. For example if a method which violates a global
    > namespace is defined inside a class I cannot get PHP to throw an error
    > when that class is instantiated. PHP will catch simple errors such as
    > lines not ending in semicolons, but doesn't catch these more 'global'
    > issues.[/color]

    What do you mean "a method which violates a global namespace?" Can you
    give an example?


    --
    Oli

    Comment

    • Nate

      #3
      Re: PHP5 Object and Class Errors

      class TestClass
      {
      public function list(){
      echo 'list';
      }
      }

      `list` is a built in PHP method, so by declaring it in an object, it
      violates the global namespace. php won't complain about this method
      being in the class, until you try to instantiate it as an object. then
      it will just fatally fail silently.

      Comment

      • Oli Filth

        #4
        Re: PHP5 Object and Class Errors

        Nate said the following on 09/04/2006 02:03:[color=blue]
        > class TestClass
        > {
        > public function list(){
        > echo 'list';
        > }
        > }
        >
        > `list` is a built in PHP method, so by declaring it in an object, it
        > violates the global namespace.[/color]

        list() is actually not a function/method, but a language construct, and
        as such, doesn't belong to any namespace.

        Use of language constructs as method names is not allowed, however, use
        of "global" function names is, replace your "list" example with "count",
        for example.
        [color=blue]
        > php won't complain about this method
        > being in the class,[/color]

        Yes it does, if you have errors set appropriately. With E_ALL, I get
        the following message:

        Parse error: parse error, unexpected T_LIST, expecting T_STRING ...


        --
        Oli

        Comment

        • Nate

          #5
          Re: PHP5 Object and Class Errors

          I guess I really shouldn't use the term namespace, I suppose what I
          meant was reserved names, or things PHP has already used so it doesn't
          want you to use them.

          So, I'm still having the issues I described and my error level is set
          to E_ALL as well according to my php.ini file.

          I'll look more into my error reporting setup, but for now, using
          language constructs in objects causes my setup to fail silently with
          errors set to E_ALL, but it's nice to know that PHP will catch these
          errors if setup correctly and that objects can have methods whose names
          are the same as global function names.

          Comment

          • Chung Leong

            #6
            Re: PHP5 Object and Class Errors


            Nate wrote:[color=blue]
            > I guess I really shouldn't use the term namespace, I suppose what I
            > meant was reserved names, or things PHP has already used so it doesn't
            > want you to use them.
            >
            > So, I'm still having the issues I described and my error level is set
            > to E_ALL as well according to my php.ini file.
            >
            > I'll look more into my error reporting setup, but for now, using
            > language constructs in objects causes my setup to fail silently with
            > errors set to E_ALL, but it's nice to know that PHP will catch these
            > errors if setup correctly and that objects can have methods whose names
            > are the same as global function names.[/color]

            I'm afriad you'll need to provide the actual code that causes the
            problem, as well as the precise version number of PHP.

            Using a reserved keyword would cause PHP to fail at the parsing stage,
            so the scenario you described shouldn't happen. Also, names of global
            functions are available as method names of a class.

            Comment

            • Wayne

              #7
              Re: PHP5 Object and Class Errors

              On 9 Apr 2006 15:19:40 -0700, "Nate" <n8agrin@gmail. com> wrote:
              [color=blue]
              >So, I'm still having the issues I described and my error level is set
              >to E_ALL as well according to my php.ini file.[/color]

              The error reporting can overridden by a error_reporting () call. You
              might want to make sure you don't have one of those (or alternatively
              put one in and set it to E_ALL).

              You definately have something wrong with your error reporting.

              Comment

              Working...