Trying to call uasort from within a model method |
[eluser]blcArmadillo[/eluser]
I'm trying to call a custom sort function from within a method in one of my models so I have something like: Code: <?php Problem is I get the following error: Quote:uasort() expects parameter 2 to be a valid callback, function 'my_sort' not found or invalid function name. I'd imagine this is because just like if you were calling the function normally from the method you'd use something like $this->my_sort('aval', 'bval'). I tried passing '$this->my_sort' into the second argument but that didn't work either. Any ideas?
[eluser]blcArmadillo[/eluser]
Is example three really the same situation? I'm trying to call sort from within one of my methods. In example three they're not calling sort from a method so they just follow the standard usage since the methods are in the local scope... right?
[eluser]Rob Gordijn[/eluser]
well, I don't think the scope is the same... uasort expects a valid callback. Normal usage is a 'normal' function, not a method within the class. maybe is array($this,'my_sort'); valid, but I doubt it since $this should be a string. maybe you can use __CLASS__ for the current classname (but does calling uasort then create a new object of the class?) [edit] weird language mixups
[eluser]danmontgomery[/eluser]
http://php.net/manual/en/function.uasort.php Code: //Note use of array to reference member method of this object in callback
[eluser]mddd[/eluser]
To add to Rob Gordijn and noctrum: you can specify either a class instance (object) or a class name (string). Both are okay.
[eluser]blcArmadillo[/eluser]
Hey everyone, Thanks for all the help. I used the snippet that noctrum posted and everything is working! |
Welcome Guest, Not a member yet? Register Sign In |