473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

BUG: Referring to a class function

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.
Jul 17 '05 #1
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
Jul 17 '05 #2
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

Jul 17 '05 #3
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.
Jul 17 '05 #4
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.
Jul 17 '05 #5
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
Jul 17 '05 #6
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

Jul 17 '05 #7
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
Jul 17 '05 #8
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

Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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++)
23
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...
12
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={}):...
77
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...
10
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...
19
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...
33
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...
8
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...
0
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...
0
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,...
0
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...
0
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...
0
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
1
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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.