...

View Full Version : Calling a static method



misterx
08-05-2008, 07:55 AM
I've made a class that contains a public static function that I can't seem to call from another file.

Here's the class stuff:


class Review {
...

public static function list( $limit = NULL ) {
...
}

}

Then in another file I'm doing this:


require( "Review.php" );

...

$reviews = Review::list( 5 );
...



But when I pull up the page that I call list from I get the following error:

Parse error: syntax error, unexpected T_LIST, expecting T_STRING or T_VARIABLE or '$' in /path/to/main.php on line 12

Is there something I'm missing or some option that needs to be changed in my PHP settings? All the examples I can find online are just like this so I don't know what the deal is. Thanks in advance.

Fou-Lu
08-05-2008, 09:41 AM
Thats correct.
There is something else wrong with you're code. I don't think this is the error that PHP4 throws off, so I'm pretty sure you have the support.
Look somewhere else in you're code, you're call is not the problem. The error you'll get for that would be along the lines of a non-existent method call in class x.

On second though, you better check to make sure you have PHP5. The keyword static isn't available in PHP4 so it may actually throw that error at you if you're in PHP4.

dumpfi
08-05-2008, 09:56 AM
list is a "special function" in PHP. It's name is reserved and thus you can't use that name anywhere else. Rename your function and the parse error should go away.

dumpfi

Fou-Lu
08-05-2008, 10:08 AM
Good catch mate!
I HATE that PHP can't overload any of its methods (even though list isn't actually a method). Bah.
Anybody here testing with PHP6 yet? I'm a little curious if the namespacing will let use redefine php functions...

misterx
08-05-2008, 03:34 PM
Gah!

I should have known. As soon as you pointed this out I noticed that Vim had made the word list green.

It doesn't do that for other functions. Thanks a lot.

derzok
08-05-2008, 05:02 PM
What's worse is when you try and select a column from a database named "lines" or "desc" or some other mysql keyword. Vim never notices these mistakes because they're usually in strings. I've spent too much of my life on bugs like this. +1 for using vim, though.

Fou-Lu
08-05-2008, 11:46 PM
The one that always gets me in sql is 'order'. Always. You'd think I'd change it to something different, but nope >.<



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum