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 3 of 3
  1. #1
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts

    PHP Class function - cannot find...

    Hi, I'm creating my mod_rewrite engine right now, and I'm having some problems with referencing a function within the class.

    heres the code:
    PHP Code:
        class query {
            private 
    $query_string;
            private 
    $raw_query;
            private 
    $fixed_query;
            
            function 
    get() {
                
    $raw_query $_SERVER['REQUEST_URI'];
                
    process_query();
            }
            
            function 
    process_query() {
                
            }
        } 
    I'm trying to get the query string through this:
    PHP Code:
    $q = new Query();
    print 
    $q->get(); 
    As you can see, in the get() function, which is the only function that I should have access to (and the function which eventually returns the processed query string), I reference a function process_query(), however, in doing so I receive this error:
    Fatal error: Call to undefined function process_query()

    I've tried using property declarations, however that doesn't work either. Any help to this matter would be greatly appreciated.
    Last edited by BWiz; 01-01-2008 at 05:26 PM.
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    when you're accessing a property or method of the object from within it, you need to use the 'special' $this variable:
    PHP Code:
    class query {
          
            function 
    get() {
                
    $raw_query $_SERVER['REQUEST_URI'];
                
    $this->process_query();
            }
            
            function 
    process_query() {
                
            }
        } 
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yes oh this drives me INSANE!
    PHP's required usage of $this is absolutly the only reason why I use 'this' in any other programming language (unless its the scope based stuff). Drives me nuts.
    Oh and by the way, you can actually access the process_query() method from the object, the default scope of php is public, unlike other languages (protected in java, internal in c#, etc), so if you don't give it a scope it assumes to be public.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

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