Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> zwracanie referencji przez funkcję
flashdev
post 8.12.2009, 00:03:49
Post #1





Grupa: Zarejestrowani
Postów: 812
Pomógł: 117
Dołączył: 2.12.2008

Ostrzeżenie: (10%)
X----


  1. // test.php
  2. <?php
  3. class test{
  4. private $variable = 'default';
  5.  
  6. public function &getVariable1(){
  7. return $this -> variable;
  8. }
  9. public function getVariable2(){
  10. $ref = &$this -> variable;
  11. return $ref;
  12. }
  13. public function &getVariable3(){
  14. $ref = &$this -> variable;
  15. return $ref;
  16. }
  17.  
  18. public function __destruct() {
  19. echo $this -> variable;
  20. }
  21. }
  22. ?>


  1. <?php
  2.  
  3. include('class/test.php');
  4. $test = new test();
  5. $variable = $test -> getVariable1();
  6. $variable = 'new value';
  7. $variable = $test -> getVariable2();
  8. $variable = 'new value';
  9. $variable = $test -> getVariable3();
  10. $variable = 'new value';
  11.  
  12. ?>


Czy potrafi mi ktoś wytłumaczyć dlaczego żadna z tych funkcji nie zwraca referencji? Da się takie coś wogóle zrobić?


--------------------
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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 11:35