[help]a simple question

Discussion in 'PHP' started by runeveryday, Aug 6, 2009.

  1. #1
    i am a newbie of php,maybe this is a simple and a little silly question,but i want to know the true principle of it.hope someone can help me .
    Q:
    there is a function,and have a form like this $a->b in a function bracket.what is $a->b mean and have what effect? the sign '->' mean is?

    eg:
    format_date($comment->timestamp)
    anyone's reply is appreciated!
     
    runeveryday, Aug 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $comment is an object and $timestamp is a property of that object. If you do not know this, it's time you buy a book instead of just teaching yourself online.
     
    premiumscripts, Aug 6, 2009 IP
  3. runeveryday

    runeveryday Active Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    thx
    i will do,i know a little.how do you know this is a class not a function?
    is see from the sign ->.
     
    runeveryday, Aug 7, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Because of -> it isn't a function. Read up on the basics. It's a variable in an object instance. If it was a method of that object it would be $comment->method()
     
    premiumscripts, Aug 7, 2009 IP
  5. oop

    oop Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    heres an example of an object

    
    
    class username(){
    
        var $username; // this will basically make an empty variable ready for use;
    
        //we now can create functions within the class object
        function printName(){
            echo $this->username; // now when were inside a function we refer to other vars outside the functions by prepending them with $this->
        }
    
        function setName($name){
            //this will be run before the above so we can fill that var $username;
            $this->username = $name; //this will fill the username with the name sent to the function
        }
    }
    
    $object = new username;
    
    //Now $object basically contains all the functions within the above class file
    
    //so now we can set the name
    $object->setName('runeveryday');
    
    //no we have done that the var $username is now = to runeveryday
    
    // now we use the other function to return the username
    echo "My name is : " . $object->getName();
    
    PHP:
    and there it is
     
    oop, Aug 7, 2009 IP
  6. runeveryday

    runeveryday Active Member

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    thanks!
    but the form of
    class username(){ }
    is right? i know the statement of a class is
    class usename{ }.
    but in your answer,it's username( ).is it right?
     
    runeveryday, Aug 7, 2009 IP