...

View Full Version : PHP4 OOP questions



chump2877
11-25-2007, 09:52 PM
I haven't done OOP with PHP4 in awhile....So I have 2 questions:

1) Can you instantiate a class if it has no constructor?

2) If a class inherits from a base class, are the base class functions publicly available via an instance of the derived class?

What I'm trying to do is prevent my base class from being instantiated directly, and prevent my base class functions from being publicly available via a derived class object.

Thanks.

GJay
11-25-2007, 10:12 PM
How long would it take you to try it and see? I can't imagine more than a couple of minutes if you have 4 installed (I don't...), but something along the lines of:


class Foo {
function bar() {}
}
$foo = new Foo();
var_dump($foo);

and


class Foo {
function fooble() {
echo "Fooble was called";
}
}

class Bar extends Foo {

}

$bar = new Bar();
$bar->fooble();


The things you're trying to do can be done easily with PHP5, so upgrade already!

ClubCosmic
11-26-2007, 12:11 PM
I want to try using php5 but my oop skills aren't the best. I'm looking onlince for resources to teach myself, but when i read about classes in php5 they seem more complicated than what i'm used to. Is there that big of a difference in php5's version? And can anyone recommended a big for a php5 beginner like me?

thanks,
c.c.

chump2877
11-26-2007, 12:31 PM
This is the best reference to learn PHP5 OOP (http://www.php.net/manual/en/language.oop5.basic.php)...It's what I used....

There are probably tutorials that are geared more towards people who aren;t familiar with OOP, but I don;t personally know of any...

PHP4 OOP is kind of a joke, since it is lacking lots of OOP features of other languages (and PHP5)...So you may want to read a book on general OOP or learn a strong OOP language (like C# -- that's what I learned) before you try to grasp the concepts of PHP5 OOP....Otherwise, I can see how the transition between PHP4 OOP and PHP5 OOP can be hard if you don;t understand the general principles of OOP.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum