Connecting Tech Pros Worldwide Forums | Help | Site Map

PHP Version 4.3.2 OO Hole???

Phil Powell
Guest
 
Posts: n/a
#1: Jul 17 '05
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
Guest
 
Posts: n/a
#2: Jul 17 '05

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

Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: PHP Version 4.3.2 OO Hole???


"Phil Powell" <soazine@erols.com> wrote in message
news:1cdca2a7.0404261320.7b149805@posting.google.c om...[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->nullExemptionArray[$section][$elementName] (useful
mainly for classes that call Accepter statically)
*
* @access public
* @param mixed $section
* @param mixed $elementName
* @return mixed $this->nullExemptionArray[$section][$elementName]
*/

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


Phil Powell
Guest
 
Posts: n/a
#4: Jul 17 '05

re: PHP Version 4.3.2 OO Hole???


"Chung Leong" <chernyshevsky@hotmail.com> wrote in message news:<aeOdnVBRh8_LWBDd4p2dnA@comcast.com>...[color=blue]
> "Phil Powell" <soazine@erols.com> wrote in message
> news:1cdca2a7.0404261320.7b149805@posting.google.c om...[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->nullExemptionArray[$section][$elementName] (useful
> mainly for classes that call Accepter statically)
> *
> * @access public
> * @param mixed $section
> * @param mixed $elementName
> * @return mixed $this->nullExemptionArray[$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
Phil Powell
Guest
 
Posts: n/a
#5: Jul 17 '05

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() {
doSomethingNonStaticHere();
}

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

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

public void doSomethingNonStaticHere() {
// BLAH BLAH BLAH
System.out.println("Blah blah blah");
}

}

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

Phil

Daniel Tryba <news_comp.lang.php@canopus.nl> wrote in message news:<c6kegl$cpn$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]
Daniel Tryba
Guest
 
Posts: n/a
#6: Jul 17 '05

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

Berislav Lopac
Guest
 
Posts: n/a
#7: Jul 17 '05

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]
http://www.phpbuilder.com/board/show...687a2615fec46e
dec19&postid=10505527#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.[/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.


Closed Thread