Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> problem z funkcją, Cannot re-assign $this
a79rtur
post 14.11.2004, 18:00:02
Post #1





Grupa: Zarejestrowani
Postów: 331
Pomógł: 1
Dołączył: 23.05.2004
Skąd: Tarnów/Londyn

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


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


--------------------
php 5.1.2 & Apache 2.0.50 & MySQL 4.1.7 @ WinXP Pro
..:: GG 6449856 ::..
www.londyn.me.uk - ogłoszenia mieszkaniowe dla Londynu
Go to the top of the page
+Quote Post
NuLL
post 14.11.2004, 18:06:32
Post #2





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

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


$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. ?>


--------------------
Javascript, Coffeescript, Node.js, Mongo, CouchDb, chmury, workery & inne bajery - zycie jest zbyt krotkie aby miec nudna prace :)
Go to the top of the page
+Quote Post
keedy
post 14.11.2004, 18:14:46
Post #3





Grupa: Zarejestrowani
Postów: 52
Pomógł: 0
Dołączył: 18.12.2003
Skąd: Gliwice

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


kto pisal ten skrypt ?


--------------------
Go to the top of the page
+Quote Post
-maciek-
post 14.11.2004, 19:33:24
Post #4





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 25.10.2004

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


Chodzi ci oto aby wywołac funkcję danej klasy dla innej klasy?


--------------------
Warsztat: Slackware 10 | Apache 2.0.52 | PHP 4.3.9 | MySQL 4.1.7 | PgSQL 7.4.6
Go to the top of the page
+Quote Post
bela
post 14.11.2004, 20:01:12
Post #5


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

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


1. Pokaż tą klase
2. W eZ pod php5 dzieje się tak samo tongue.gif


--------------------
Go to the top of the page
+Quote Post
a79rtur
post 14.11.2004, 20:08:46
Post #6





Grupa: Zarejestrowani
Postów: 331
Pomógł: 1
Dołączył: 23.05.2004
Skąd: Tarnów/Londyn

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


oto link do klasy : >KLIK<


--------------------
php 5.1.2 & Apache 2.0.50 & MySQL 4.1.7 @ WinXP Pro
..:: GG 6449856 ::..
www.londyn.me.uk - ogłoszenia mieszkaniowe dla Londynu
Go to the top of the page
+Quote Post
dr_bonzo
post 14.11.2004, 22:01:27
Post #7





Grupa: Przyjaciele php.pl
Postów: 5 724
Pomógł: 259
Dołączył: 13.04.2004
Skąd: N/A

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


  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.

Ten post edytował dr_bonzo 14.11.2004, 22:26:19


--------------------
Nie lubię jednorożców.
Go to the top of the page
+Quote Post
a79rtur
post 14.11.2004, 23:31:33
Post #8





Grupa: Zarejestrowani
Postów: 331
Pomógł: 1
Dołączył: 23.05.2004
Skąd: Tarnów/Londyn

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


dzieki za wyczerpujacą odpowiedź


--------------------
php 5.1.2 & Apache 2.0.50 & MySQL 4.1.7 @ WinXP Pro
..:: GG 6449856 ::..
www.londyn.me.uk - ogłoszenia mieszkaniowe dla Londynu
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: 8.07.2025 - 03:10