Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Calling a static method

    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:
    PHP Code:
    class Review {
    ...

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


    Then in another file I'm doing this:
    PHP Code:
    require( "Review.php" );

    ...

    $reviews Review::list( );
    ... 
    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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    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
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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...
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    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.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The one that always gets me in sql is 'order'. Always. You'd think I'd change it to something different, but nope >.<
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •