Re: Help with OOPHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 1/11/2007, at 5:48, Andrew Peterson wrote:

I'm hoping you guys can help me out.

I'm not sure if you can do this, but i'm trying to create a class that is build of another class. I also want to be able to do functions on the class1 from within class2.


example:

class fruitBasket{

	private $fuit = array();  //this is a class

mispelt variable? you use $fruit later on.



	public function addFruit($newFruit)
	{
		$this->fruitBasket[] = $newFruit();

a) you're using the wrong variable.
b) you're calling the function with the name stored in $newFruit. Maybe you want to use:

$this->fruit[] = new fruit($newFruit);


	}

	public makeAllApples()
	{
		foreach($this->fruit AS $value)
		{		
			$value->changeName("apple");
		}	
	}

}



class fruit{

	private $name;

	public __construct($name)
	{
		$this->name = $name;
	}

	public changeName($newName)
	{
		$this->name = $newName;
	}
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Simon Welsh
Admin of http://simon.geek.nz/

Windows is a joke operating system. Hell, it's not even an operating system. NT is Not Tough enough for me either. 95 is how may times it will crash an hour.

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux