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!
$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.
thx i will do,i know a little.how do you know this is a class not a function? is see from the sign ->.
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()
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
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?