Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klasa zwraca samą siebie
tadeurz
post
Post #1





Grupa: Zarejestrowani
Postów: 70
Pomógł: 1
Dołączył: 25.04.2009

Ostrzeżenie: (0%)
-----


Mam problem, nie wiem czy jest to wogóle możliwe.Mam 2 klasy Element i Box, chce żeby wywołanie metody Element.save() zwróciło samą siebie do metody Box.storeElements()
  1. class Box{
  2. public static function storeElement($element){
  3. if( $element->type == 'red' ) self::goToRedElements();
  4. else self::goToDefaultElements();
  5. }
  6. }
  7. class Element{
  8. private type = 'default';
  9. public function save(){
  10. $this->type = 'red';
  11. box::storeElement(this); //tutaj jak zwrócić instancje obiektu Element ?
  12. }
  13. }
  14. /**************************/
  15. $element = new Element();
  16. $element->save();
  17.  
  18. //nie chce tego robić tak:
  19. $element = new Element();
  20. $element->save();
  21. //z metody save() wylatuje wywołanie box::storeElement();
  22. box::storeElement($element);


Ten post edytował tadeurz 4.03.2013, 02:00:53
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 05:01