Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: problem z funkcją
Forum PHP.pl > Forum > PHP
a79rtur
mam problem z następująca funkcją uzytą w pewnej klasie
wyskakuje błąd:

Fatal error: Cannot re-assign $this in ...

  1. <?php
  2.  
  3. function copy($other) {
  4. $xf = $this->_xf_index;
  5. $this = $other;  <-- ta linia 
  6. $this->_xf_index = $xf;  
  7. }
  8.  
  9. ?>

moze to php5 wina ,bo klasa nie najnowsza 2002r
NuLL
$this jest identyfikatorem ktory pozwala sie poruszac wewnatrz klasy i jej skladowych, funckji, metod. Samemu $this'owi nie mozna niczego przypisac- jest mowiac prosto zarezerowany. W sumie - co to robi questionmark.gif

moze poprostu:
  1. <?php
  2.  
  3. ....
  4. $other=$this; // tutaj mzmiennej $other przypisujemy to co jest w $this
  5. ....
  6.  
  7. ?>
keedy
kto pisal ten skrypt ?
-maciek-
Chodzi ci oto aby wywołac funkcję danej klasy dla innej klasy?
bela
1. Pokaż tą klase
2. W eZ pod php5 dzieje się tak samo tongue.gif
a79rtur
oto link do klasy : >KLIK<
dr_bonzo
  1. <?php
  2.  
  3. function copy($other) {
  4.         $xf = $this->_xf_index;   // Backup XF index
  5.         $this = $other;           // Copy properties
  6.         $this->_xf_index = $xf;   // Restore XF index
  7.     }
  8.  
  9. ?>


(http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-0.37/WriteExcel/doc/WriteExcel.html):
Cytat
copy($format)

This method is used to copy all of the properties from one Format object to another:


    my $lorry1 = $workbook->addformat();
    $lorry1->set_bold();
    $lorry1->set_italic();
    $lorry1->set_color('red');    # lorry1 is bold, italic and red


    my $lorry2 = $workbook->addformat();
    $lorry2->copy($lorry1);
    $lorry2->set_color('yellow'); # lorry2 is bold, italic and yellow

It is only useful if you are using the method interface to Format properties. It generally isn't required if you are setting Format properties directly using hashes.

Note: this is not a copy constructor, both objects must exist prior to copying.


czyli ta funkcja probuje przypisac aktualnie uzywanemu obiektowi obiekt podany jako argument funkcji copy, jak widac jest to nieprawidlowe w php.

Cytat
This method is used to copy all of the properties from one Format object to another:


wiec moze obejdziesz sie bez tej funkcji (usun ja z kodu), lub przepisz ja tak zeby recznie skopiwac wszystkie "properties" (jak to jest po polsku?) z obiektu podanego w argumencie funkcji:
  1. <?php
  2.  
  3. $this->_font_index = $other->_font_index
  4. // ... itd az do
  5. //_right_color;
  6. // patrz poczatek tej klasy
  7. // niekopiuj tylko $this->_xf_index;
  8.  
  9. ?>


Nie sprawdzalem czy dziala!

---------------------------------------------------------
(http://www.ez.no/community/forum/install_configuration/installing_ez_publish_3_4_fatal_error_cannot_re_assign_this_in_ezdebug_php)
Cytat
Re: Installing eZ publish 3.4: "Fatal error: Cannot re-assign $this in ezdebug.php"
Posted on: Monday 21 June 2004 5:07:02 pm

We do not currently support PHP5. PHP5 will require some of the code to be rewritten, something we'll do when PHP5 is more widespread, and proven stable.

To jest chyba wina PHP5, 4ce bylo to chyba mozwliwe.
a79rtur
dzieki za wyczerpujacą odpowiedź
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.