This is a "namespace" problem with "::". Is there an official place I
can report php bugs? I'm new to PHP (and soon to be leaving it):
class SomeClass {
function dostuff($ar) {
uasort($ar, 'SomeClass::somesort');
}
function somesort($a,$b) {<-- never gets called
echo "Yes I got called"; //<-- never happens
if ($a[order] == $b[order]) { return 0;}
if ($a[order] < $b[order]) { return -1;};
if ($a[order] > $b[order]) { return 1;};
}
}
SomeClass::dostuff($ar); //put whatever you want in the $ar array to
test
In the line "uasort($ar, 'SomeClass::somesort');",
'SomeClass::somesort' isn't recognized by PHP. I also tried just
'somesort', no go.
I was trying to use a class as a substitute for PHP's lack of
namespaces. (Which btw is the reason I'm bailing out of php.)
Because of this bug I have to put my sorting funct into the global
space, which is ridiculous. 8 2712
mrbog wrote: This is a "namespace" problem with "::". Is there an official place I can report php bugs? I'm new to PHP (and soon to be leaving it):
class SomeClass { function dostuff($ar) { uasort($ar, 'SomeClass::somesort'); }
function somesort($a,$b) {<-- never gets called echo "Yes I got called"; //<-- never happens if ($a[order] == $b[order]) { return 0;} if ($a[order] < $b[order]) { return -1;}; if ($a[order] > $b[order]) { return 1;}; } } SomeClass::dostuff($ar); //put whatever you want in the $ar array to test
In the line "uasort($ar, 'SomeClass::somesort');", 'SomeClass::somesort' isn't recognized by PHP. I also tried just 'somesort', no go.
I was trying to use a class as a substitute for PHP's lack of namespaces. (Which btw is the reason I'm bailing out of php.) Because of this bug I have to put my sorting funct into the global space, which is ridiculous.
Why are you using :: rather than creating an instance of the class? i.e.
$foo = new SomeClass;
when you use a class function as a callback one usually uses the $this
pointer, however as you didn't create an instance of the class then you
can't, I don't think this is a bug, I think the problem is that you
aren't using classes properly.
~Cameron
mrbog writes: This is a "namespace" problem with "::". Is there an official place I can report php bugs? I'm new to PHP (and soon to be leaving it):
Patience. If you let this small problem frustrate you, you'll have
just as many problems whatever language you choose.
uasort($ar, 'SomeClass::somesort');
Change this line to uasort($ar, array('SomeClass', 'somesort') );
--
__o Alex Farran
_`\<,_ Analyst / Programmer
(_)/ (_) www.alexfarran.com
Why not do the following:
class SomeClass{
function dostuff($ar)
{
function SomeSort($a, $b)
{
/* Your sorting code goes here. */
}
uasort($ar, 'SomeSort');
}
}/* End class */
Thus nothing, but the required function will see the sorting function. Isn't
that peachy?
root-boy.
Cameron <fo*@bar.invalid> wrote in message news:<c0**********@newsg2.svr.pol.co.uk>... Why are you using :: rather than creating an instance of the class? i.e.
$foo = new SomeClass;
when you use a class function as a callback one usually uses the $this pointer, however as you didn't create an instance of the class then you can't, I don't think this is a bug, I think the problem is that you aren't using classes properly.
~Cameron
It's called a static function. PHP supports referring to functions
that way, otherwise I wouldn't have been able to do the line
"SomeClass::dostuff($ar);" which does work. As I said, I'm using
classes to accomodate PHP's (terribly unfortunate) lack of namespaces.
Alex Farran <al**@alexfarran.com> wrote in message news:<m3************@alexfarran.com>... mrbog writes:
Patience. If you let this small problem frustrate you, you'll have just as many problems whatever language you choose.
Lack of namespaces is not a small problem. uasort($ar, 'SomeClass::somesort'); Change this line to uasort($ar, array('SomeClass', 'somesort') );
Thanks very much, it worked. Don't know why they can't have PHP just
check for "::" in the name and do this for me. But thanks again.
(Hey is there an official place I can report bugs or is this the
place? Not that this was a bug per se, I'm just asking in general.
Maybe I could make it a "suggestion".)
thanks,
mrb
mrbog writes: > uasort($ar, 'SomeClass::somesort'); Change this line to uasort($ar, array('SomeClass', 'somesort') );
Thanks very much, it worked. Don't know why they can't have PHP just check for "::" in the name and do this for me. But thanks again. (Hey is there an official place I can report bugs or is this the place? Not that this was a bug per se, I'm just asking in general. Maybe I could make it a "suggestion".)
I expect you'll find all you need at www.php.net.
--
__o Alex Farran
_`\<,_ Analyst / Programmer
(_)/ (_) www.alexfarran.com
mrbog wrote: Cameron <fo*@bar.invalid> wrote in message news:<c0**********@newsg2.svr.pol.co.uk>...
Why are you using :: rather than creating an instance of the class? i.e.
$foo = new SomeClass;
when you use a class function as a callback one usually uses the $this pointer, however as you didn't create an instance of the class then you can't, I don't think this is a bug, I think the problem is that you aren't using classes properly.
~Cameron
It's called a static function. PHP supports referring to functions that way, otherwise I wouldn't have been able to do the line "SomeClass::dostuff($ar);" which does work. As I said, I'm using classes to accomodate PHP's (terribly unfortunate) lack of namespaces.
I know what it is.
~Cameron
That a programmer should feel he cannot do without namespace is a sad
commentary on the break-down of our PHP community. Shared values and
assumptions have so diminished that we cannot function without segregating
ourselves into little cocoons. It's as though relativism has reached its
apex, and in the world in which we program, not only can we not agree what
ideas mean, we cannot even agree on which name is associated with with idea.
Uzytkownik "mrbog" <dt******@hotmail.com> napisal w wiadomosci
news:cb*************************@posting.google.co m... Alex Farran <al**@alexfarran.com> wrote in message
news:<m3************@alexfarran.com>... mrbog writes:
Patience. If you let this small problem frustrate you, you'll have just as many problems whatever language you choose.
Lack of namespaces is not a small problem.
uasort($ar, 'SomeClass::somesort'); Change this line to uasort($ar, array('SomeClass', 'somesort') );
Thanks very much, it worked. Don't know why they can't have PHP just check for "::" in the name and do this for me. But thanks again. (Hey is there an official place I can report bugs or is this the place? Not that this was a bug per se, I'm just asking in general. Maybe I could make it a "suggestion".)
thanks, mrb This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nomen Nescio |
last post by:
I say its a bug. What do you think?
public class test
public static void main(String args)
int n
Integer I
I = new Integer(0)
for (int i = 0 i < 5 i++)
|
by: Yannick Patois |
last post by:
Hi,
Under some naming conditions of module files, it seems that python lost
class static variables values.
It seems only to append when importing a "badly" named module that
itself import a...
|
by: David MacQuigg |
last post by:
I have what looks like a bug trying to generate new style classes with
a factory function.
class Animal(object): pass
class Mammal(Animal): pass
def newAnimal(bases=(Animal,), dict={}):...
|
by: nospam |
last post by:
Reasons for a 3-tier achitecture for the WEB?
(NOTE: I said, WEB, NOT WINDOWS.
DON'T shoot your mouth off if you don't understand the difference.)
I hear only one reason and that's to switch a...
|
by: Ryan McGeary |
last post by:
In a <select> drop-down, the onchange event isn't called when
scrolling through the dropdown using the mouse-wheel and when crossing
over a new <optgroup>.
Using the example below, notice how...
|
by: Martin Oddman |
last post by:
Hi,
I have a compiling problem. Please take a look at the code below.
I have an application that is built upon three tiers: one data tier
(Foo.DataManager), one business tier (Foo.Kernel) and...
|
by: Ken |
last post by:
I have a C# Program where multiple threads will operate on a same Hashtable.
This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable)
method, so no further Lock statements are...
|
by: gw7rib |
last post by:
I've been bitten twice now by the same bug, and so I thought I would
draw it to people's attention to try to save others the problems I've
had. The bug arises when you copy code from a destructor...
|
by: Kurt B. Kaiser |
last post by:
Patch / Bug Summary
___________________
Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42)
Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86)
RFE : 262 open...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |