Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Dane składowe klasy głównej w klasach pochodnych
Kmils21
post 22.02.2014, 12:05:25
Post #1





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 29.12.2010

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


  1. <?php
  2. abstract class test{
  3. public $b;
  4.  
  5. public function a(){
  6. $this -> b = 10;
  7. }
  8. public function b(){
  9. return $this -> b;
  10. }
  11. }
  12. class test2 extends test{
  13.  
  14. public function __construct(){
  15. parent::a();
  16. }
  17.  
  18. }
  19. class test3 extends test{
  20.  
  21. public function __construct(){
  22. echo parent::b();
  23. }
  24.  
  25. }
  26. new test2;
  27. new test3;
  28. ?>

Dlaczego to nie działa?
Jak zrobić, żeby działało?

Jak w klasie test3 pobrac dane z klasy test, które ustawiam w klasie test za pomocą klasy test2?

Ten post edytował Kmils21 22.02.2014, 12:08:14


--------------------
Go to the top of the page
+Quote Post
Spawnm
post 22.02.2014, 12:17:00
Post #2





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




Użyj static.
  1. abstract class test{
  2. public static $b;
  3.  
  4. public function a(){
  5. self::$b = 10;
  6. }
  7. public function b(){
  8. return self::$b;
  9. }
  10. }
Go to the top of the page
+Quote Post
Kmils21
post 22.02.2014, 12:47:56
Post #3





Grupa: Zarejestrowani
Postów: 128
Pomógł: 0
Dołączył: 29.12.2010

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


Tak też zrobię. Dzięki za pomoc.


--------------------
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 23.04.2024 - 17:01