PHP Version 4.3.2 OO Hole??? – PHP

  php

Q(Question):

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

A(Answer):

Phil Powell <so*****@erols.com> wrote:

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.

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

A(Answer):

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om…

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

/**
* 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?

A(Answer):

"Chung Leong" <ch***********@hotmail.com> wrote in message news:<ae********************@comcast.com>…

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om…

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

/**
* 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?

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

A(Answer):

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 <ne****************@canopus.nl> wrote in message news:<c6**********@news.tue.nl>…

Phil Powell <so*****@erols.com> wrote:

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.

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".

A(Answer):

Phil Powell <so*****@erols.com> wrote:

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

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

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

A(Answer):

Phil Powell wrote:

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…687a2615fec46e
dec19&postid=10505527#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.

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.

LEAVE A COMMENT