lists.zerezo.com



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

***BOGO*** Re: [PHP] include methods of one class in another



On Thu, Aug 21, 2008 at 6:10 AM, Pavel <rapkasta@xxxxxxxxx> wrote:
> Hello, firstly, sorry for my English...
>
> I have class:
> //---
> class manageClassError{
>    private $errorsList=array();
>
>
>    private function addError($ex){
>        $errorsList[]=$ex;
>    }
>    public function isError(){
>        return (bool)(count($this->errorsList));
>    }
>    public function getErrorsList(){
>        return $this->errorsList;
>    }
>    public function returnLastError(){
>        $cErrorsList=count($this->errorsList);
>        If($cErrorsList==0){
>            return false;
>        }else{
>            return $this->errorsList[$cErrorsList-1];
>        }
>    }
>
> }
> //---
> this class alone can't do anything practicality, but if "include" this class
> to another it can salve other class to copy code of first class...
>
> so i had many class,which contain all method of   manageClassError and i need
> to mark managing error in other class...can you help me?
>
> P.S. I think, use "extends" isn't good for my idea...
>
> --
> ===============
> С уважением, Манылов Павел aka [R-k]
> icq: 949-388-0
> mailto:rap-kasta@xxxxxxx
> ===============
> А ещё говорят так:
> I was at this restaurant.  The sign said "Breakfast Anytime."  So I
> ordered French Toast in the Rennaissance.
>                -- Steven Wright
> [fortune]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You can make your error class a singleton, perhaps make the methods
static, or use some sort of dependency injection.  This way you can
call it from your other classes.

Two quick examples:

class foo {

	/**
	 * @var manageClassError
	 */
	protected $error;

	public function __construct(manageClassError $error) {
		$this->error = $error;
	}
	
	public function process() {
		$this->error->addError('uh oh');
	}

}


or

class foo {	
	public function process() {
		$error = manageClassError::getInstance();
		$error->addError('uh oh');
	}
}