PHP Version 4.3.2 OO Hole???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Powell

    PHP Version 4.3.2 OO Hole???

    I might have found a rather bad hole in PHP OO design for Versions
    4.3.2 involving static class-level rendering, like in Java. Please
    read my thread at http://www.phpbuilder.com/board/show...7#post10505527
    and please, if you have a counter to this, I'm all ears. Based on
    what I have found so far, nothing seems to address this, not even in
    the manual.

    Phil
  • Daniel Tryba

    #2
    Re: PHP Version 4.3.2 OO Hole???

    Phil Powell <soazine@erols. com> wrote:[color=blue]
    > I might have found a rather bad hole in PHP OO design for Versions
    > 4.3.2 involving static class-level rendering, like in Java. Please
    > read my thread at http://www.phpbuilder.com/board/show...7#post10505527[/color]
    [color=blue]
    > and please, if you have a counter to this, I'm all ears. Based on
    > what I have found so far, nothing seems to address this, not even in
    > the manual.[/color]

    The PHP code you posted is equivalent to the following java code:

    class Foo
    {
    public static String foo="Foo";

    public static String bar()
    {
    return this.foo;
    }
    }

    IOW It doesn't work.

    And since you can't access a variable in a static way (in php4), there
    is no equivalent for:
    class Foo
    {
    public static String foo="Foo";

    public static String bar()
    {
    return Foo.foo;
    }
    }

    With http://www.php.net/manual/en/functio...class-vars.php one can
    access the defaults but the example clearly shows that it's not the
    solution to your "problem".

    --

    Daniel Tryba

    Comment

    • Chung Leong

      #3
      Re: PHP Version 4.3.2 OO Hole???

      "Phil Powell" <soazine@erols. com> wrote in message
      news:1cdca2a7.0 404261320.7b149 805@posting.goo gle.com...[color=blue]
      > I might have found a rather bad hole in PHP OO design for Versions
      > 4.3.2 involving static class-level rendering, like in Java. Please
      > read my thread at[/color]
      http://www.phpbuilder.com/board/show...7#post10505527[color=blue]
      > and please, if you have a counter to this, I'm all ears. Based on
      > what I have found so far, nothing seems to address this, not even in
      > the manual.
      >
      > Phil[/color]

      /**
      * Retrieve $this->nullExemptionA rray[$section][$elementName] (useful
      mainly for classes that call Accepter statically)
      *
      * @access public
      * @param mixed $section
      * @param mixed $elementName
      * @return mixed $this->nullExemptionA rray[$section][$elementName]
      */

      Hmmm...very interesting OO technique here. Care to explain what the code
      does?


      Comment

      • Phil Powell

        #4
        Re: PHP Version 4.3.2 OO Hole???

        "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<aeOdnVBRh 8_LWBDd4p2dnA@c omcast.com>...[color=blue]
        > "Phil Powell" <soazine@erols. com> wrote in message
        > news:1cdca2a7.0 404261320.7b149 805@posting.goo gle.com...[color=green]
        > > I might have found a rather bad hole in PHP OO design for Versions
        > > 4.3.2 involving static class-level rendering, like in Java. Please
        > > read my thread at[/color]
        > http://www.phpbuilder.com/board/show...7#post10505527[color=green]
        > > and please, if you have a counter to this, I'm all ears. Based on
        > > what I have found so far, nothing seems to address this, not even in
        > > the manual.
        > >
        > > Phil[/color]
        >
        > /**
        > * Retrieve $this->nullExemptionA rray[$section][$elementName] (useful
        > mainly for classes that call Accepter statically)
        > *
        > * @access public
        > * @param mixed $section
        > * @param mixed $elementName
        > * @return mixed $this->nullExemptionA rray[$section][$elementName]
        > */
        >
        > Hmmm...very interesting OO technique here. Care to explain what the code
        > does?[/color]

        That in and of itself does nothing in PHP, but is parsed by
        PHPDocumentor (http://www.phpdocumentor.com) for building Javadoc-like
        documents for PHP.

        Phil

        Comment

        • Phil Powell

          #5
          Re: PHP Version 4.3.2 OO Hole???

          The PHP code I'm trying to write, however, will be the equivalent of this:

          public class Foo {

          public Foo() {
          doSomethingNonS taticHere();
          }

          public static final String[] fooArray = "{'blah', 'whatever', 'etc.'}";

          public static String getFooValue(int i) {
          return fooArray[i];
          }

          public void doSomethingNonS taticHere() {
          // BLAH BLAH BLAH
          System.out.prin tln("Blah blah blah");
          }

          }

          out.println(Foo .getFooValue(1) );

          Phil

          Daniel Tryba <news_comp.lang .php@canopus.nl > wrote in message news:<c6kegl$cp n$1@news.tue.nl >...[color=blue]
          > Phil Powell <soazine@erols. com> wrote:[color=green]
          > > I might have found a rather bad hole in PHP OO design for Versions
          > > 4.3.2 involving static class-level rendering, like in Java. Please
          > > read my thread at http://www.phpbuilder.com/board/show...7#post10505527[/color]
          >[color=green]
          > > and please, if you have a counter to this, I'm all ears. Based on
          > > what I have found so far, nothing seems to address this, not even in
          > > the manual.[/color]
          >
          > The PHP code you posted is equivalent to the following java code:
          >
          > class Foo
          > {
          > public static String foo="Foo";
          >
          > public static String bar()
          > {
          > return this.foo;
          > }
          > }
          >
          > IOW It doesn't work.
          >
          > And since you can't access a variable in a static way (in php4), there
          > is no equivalent for:
          > class Foo
          > {
          > public static String foo="Foo";
          >
          > public static String bar()
          > {
          > return Foo.foo;
          > }
          > }
          >
          > With http://www.php.net/manual/en/functio...class-vars.php one can
          > access the defaults but the example clearly shows that it's not the
          > solution to your "problem".[/color]

          Comment

          • Daniel Tryba

            #6
            Re: PHP Version 4.3.2 OO Hole???

            Phil Powell <soazine@erols. com> wrote:[color=blue]
            > The PHP code I'm trying to write, however, will be the equivalent of this:
            >
            > public static final String[] fooArray = "{'blah', 'whatever', 'etc.'}";[/color]

            This is a final array, so can't be changed... in this case
            http://www.php.net/manual/en/functio...class-vars.php actually is the
            answer.

            --

            Daniel Tryba

            Comment

            • Berislav Lopac

              #7
              Re: PHP Version 4.3.2 OO Hole???

              Phil Powell wrote:[color=blue]
              > I might have found a rather bad hole in PHP OO design for Versions
              > 4.3.2 involving static class-level rendering, like in Java. Please
              > read my thread at
              >[/color]

              dec19&postid=10 505527#post1050 5527[color=blue]
              > and please, if you have a counter to this, I'm all ears. Based on
              > what I have found so far, nothing seems to address this, not even in
              > the manual.[/color]

              PHP 4 doesn't have static object properties. So, when you call a class's
              method without instantiating the object first, it is executed just like any
              other function; the class gives it only a specific namespace. Since there is
              no object, there can't be a reference to it, and therefore the $this
              variable is not set.

              You are correct, PHP4 is miles away from Java when it comes to completeness
              of its OO features. PHP5 is bound to amend a lot of the differences.

              Berislav

              --
              If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
              Groucho, Chico, and Harpo, then Usenet is Zeppo.


              Comment

              Working...