upcasting in PHP OOP

This is a discussion on upcasting in PHP OOP within the PHP Language forums, part of the PHP Programming Forums category; Lets suppose I have an class called DatastoreSelect. It has a method called getNextRow(). This method is not abstract, it ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-17-2003
lawrence
 
Posts: n/a
Default upcasting in PHP OOP

Lets suppose I have an class called DatastoreSelect. It has a method
called getNextRow(). This method is not abstract, it is fully
implemented. It also has a method called setInfoToBeSought, which is
abstract in the sense that it has no implementation.

Now suppose I have an class called GetAllComments, which inherits from
DatastoreSelect. GetAllComments does not have a method called
getNextRow(). GetAllComments has a method called setInfoToBeSought,
which contains some SQL, like this:

$query = "SELECT * FROM content WHERE type='comments' AND
page=$pageId";

GetAllComments also has a method called getInfo() which gets runs the
query and gets a resource pointer.

Can I do this:

$gac = new GetAllComments();
$gac->setInfoToBeSought($pageId);
$gac->getInfo();
$datastoreReturn = $gac->getNextRow();


I mean, can I act like the method getNextRow() is there, even though
it's implementation is in the parent class?

If not, how else does one use the methods in super classes? Is there a
way to do Java-style upcasting?
Reply With Quote
  #2 (permalink)  
Old 11-17-2003
warstar
 
Posts: n/a
Default Re: upcasting in PHP OOP

On 17 Nov 2003 12:32:28 -0800, lkrubner@geocities.com (lawrence)
wrote:

>Lets suppose I have an class called DatastoreSelect. It has a method
>called getNextRow(). This method is not abstract, it is fully
>implemented. It also has a method called setInfoToBeSought, which is
>abstract in the sense that it has no implementation.
>
>Now suppose I have an class called GetAllComments, which inherits from
>DatastoreSelect. GetAllComments does not have a method called
>getNextRow(). GetAllComments has a method called setInfoToBeSought,
>which contains some SQL, like this:
>
>$query = "SELECT * FROM content WHERE type='comments' AND
>page=$pageId";
>
>GetAllComments also has a method called getInfo() which gets runs the
>query and gets a resource pointer.
>
>Can I do this:
>
>$gac = new GetAllComments();
>$gac->setInfoToBeSought($pageId);
>$gac->getInfo();
>$datastoreReturn = $gac->getNextRow();
>
>
>I mean, can I act like the method getNextRow() is there, even though
>it's implementation is in the parent class?

Yeah u can
>
>If not, how else does one use the methods in super classes? Is there a
>way to do Java-style upcasting?


Yeah u can
Reply With Quote
  #3 (permalink)  
Old 11-17-2003
Pedro Graca
 
Posts: n/a
Default Re: upcasting in PHP OOP

lawrence wrote:
> Lets suppose I have an class called DatastoreSelect. It has a method
> called getNextRow(). [...]
>
> Can I do this:
>
> $gac = new GetAllComments();
> $gac->setInfoToBeSought($pageId);
> $gac->getInfo();
> $datastoreReturn = $gac->getNextRow();
>
>
> I mean, can I act like the method getNextRow() is there, even though
> it's implementation is in the parent class?
>
> If not, how else does one use the methods in super classes? Is there a
> way to do Java-style upcasting?


What happenned when you tried?

When I tried this

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<?php
class x1 {
function out() {echo 'x1::out';}
}

class x2 extends x1 {
function out2() {echo 'x2::out';}
}

$z = new x2;

$z->out();
echo "\n\n";
$z->out2();
echo "\n\n";
?>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


I got this back

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
x1::out

x2::out

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

--
..sig
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:55 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0