jmDesktop wrote:
On Sep 16, 12:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>jmDesktop wrote:
>>On Sep 16, 12:25 pm, jmDesktop <needin4mat...@gmail.comwrote:
http://php.net/manual/en/language.oop5.visibility.php
Why does it print out below like it says it does? Why doesn't it
print out just foo's methods?
Thanks.
class Bar
{
public function test() {
$this->testPrivate();
$this->testPublic();
}
public function testPublic() {
echo "Bar::testPublic\n";
}
private function testPrivate() {
echo "Bar::testPrivate\n";
}
}
class Foo extends Bar
{
public function testPublic() {
echo "Foo::testPublic\n";
}
private function testPrivate() {
echo "Foo::testPrivate\n";
}
}
$myFoo = new foo();
$myFoo->test(); // Bar::testPrivate
// Foo::testPublic
because foo's is private and bar can't see it. but when I changed
foo's to public testPrivate, it still showed bar's. I had to make the
both public to see foo's.
That is correct operation. Even though Foo's method is public, Bar's is
private. So Bar::test() only looks at the private function.
To overload a function in a derived class, both base and derived class
functions must be public.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
- Show quoted text -
Is that just the way that PHP handles overriding (it isn't really
overloading is it)? I don't remember that way being anything specific
for oop. I know some have the word virtual and overrid like C#. Or
the derived just overrides by default. I think Java does it that way.
That's the way C++, Java and SmallTalk handle it, and it's a basic
principal of OO. I don't know how c# does it - but it wouldn't surprise
me if it didn't follow OO principles.
And it isn't really overriding, either - it's actually polymorphism.
But I don't like to use too many long words because of some of the
trolls in this newsgroup :-).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================