![]() |
![]() |
|
![]() |
![]() |
|
Programmierung Rat & Tat für Programmierer |
![]() |
|
Themen-Optionen | Ansicht |
![]() |
#1 |
Hero
![]() |
![]() PHP:
Wenn ich in der Compare-Funktion zu uasort auf $this->categories zugreife, erhalte ich die Fehlermeldung: "Fatal error: Using $this when not in object context in" Ich erhalte diese Fehlermeldung auch dann, wenn ich diese Funktion lokal als Unterfunktion in der Klasse selber aufrufe. Ich rufe es auf mit: Code:
uasort ($productsArray[$v], "categorycomp"); Code:
$categories1=array(); // It is a copy of $this->categories to make asort possible function categorycomp($row1, $row2) { global $categories1; debug($this->categories1,'$this->categories1', __LINE__, __FILE__); debug($categories1,'$categories1', __LINE__, __FILE__); return strcmp($categories1[$row1['category']], $categories1[$row2['category']]); } Code:
class tx_ttproducts { var $categories=array(); Wie muß ich die $this-Variablen oder andere Variablen korrekt an die Compare-Funktion in uasort übergeben? ![]() wenn ich es als Klassen-Member implementiere, erhalte ich: "Warning: uasort() [function.uasort]: Invalid comparison function. in" Code:
uasort ($productsArray[$v], "main_products::categorycomp");
____________________________________
Bibel |
![]() |
![]() |
![]() |
#2 |
Hero
![]() |
![]() Ich habe jetzt eine Lösung gefunden:
Beim Aufruf Code:
global $categories1; $categories1 = $this->categories; Aber gibt es eine Möglichkeit, die Compare-Funktion als Klassen-Methode zu implementieren, damit ich direkt über $this->categories dort zugreifen kann?
____________________________________
Bibel |
![]() |
![]() |
![]() |
#3 |
Inventar
![]() Registriert seit: 04.11.2001
Alter: 45
Beiträge: 2.150
|
![]() uasort(..., array(&$this, 'compareFunc'));
RTFM ![]() ~
____________________________________
LOL - Mein erstes Post im Programmier Forum MACINTOSH - Most Applications Crash, If Not The Operating System Hangs |
![]() |
![]() |
![]() |
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1) | |
|
|