RE: [PHP] Inherited Arrays within objects problem.
| From: | Cal Evans | Date: | Sat, 23 Dec 2000 13:33:59 +0000 |
| Subject: | RE: [PHP] Inherited Arrays within objects problem. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-31672@lists.php.net to get a copy of this message | ||
No, the actual code part of a shopping cart I'm building.
Cal
-----Original Message-----
From: Cynic [mailto:cynic@mail.cz]
Sent: Friday, December 22, 2000 11:16 PM
To: Cal Evans; php-general@lists.php.net
Subject: Re: [PHP] Inherited Arrays within objects problem.
Ok, I assume that _wasn't_ actual code, was it? It throws up
a parse error on myArray($name) and on $this-myArray($name)
(of course: should be $this->myArray[$name] ).
And, as far as my computer is concerned, this works (of course):
class one
{
function one(){
$this->myArray = array();
}
function addRow($name,$stuff){
$this->myArray[$name]=$stuff;
}
function removeRow($name){
unset($this->myArray[$name]);
}
}
class two extends one
{
function two(){
$this->one();
}
}
$x = new two() ;
var_dump( $x ) ;
$x->addrow( 'offset' , 'data' );
var_dump( $x ) ;
$x->removerow( 'offset' ) ;
var_dump( $x ) ;
output is:
At 06:03 23.12. 2000, Cal Evans wrote the following:
--------------------------------------------------------------
>I'm seriously confused.
>
>I have two classes:
>
>class one {
> function one(){
> $this->myArray = array();
> }
>
> function addRow($name,$stuff){
> $this->myArray($name)=$stuff;
> }
>
> function removeRow($name){
> unset($this-myArray($name));
> }
>}
>
>class two extends one{
>
> function two(){
> $this->one();
> }
>
>}
>
>Now if I instantiate one, I can add and remove rows form the array. If I
>instantiate two, I can add rows but never remove them. I've tried
>array_splice and unset. within the function two->removeRow() the count
drops
>by one but once I'm outside of the function, it goes back to the original
>size.
>
>Anyone got ANY idea what I'm doing wrong here?
>TIA,
>Cal
>
>*
>* Professional Nerd Herder
>* http://www.calevans.com
>*
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
------end of quote------
____________________________________________________________
Cynic:
A member of a group of ancient Greek philosophers who taught
that virtue constitutes happiness and that self control is
the essential part of virtue.
cynic@mail.cz