Page 1 of 1

What is this doing?

Posted: Thu Apr 07, 2011 8:04 am
by spacebiscuit
Can someone let me know what the following code is doing:

Code: Select all

start_on = new DateTime($start_on); 
$this->end_on = new DateTime($end_on);
Thanks,

Rob.

Re: What is this doing?

Posted: Thu Apr 07, 2011 9:35 am
by social_experiment
It looks like objects are being instantiated

Re: What is this doing?

Posted: Thu Apr 07, 2011 9:39 am
by spacebiscuit
More specifically what does the '->' do/mean:

$this->end_on

Thanks,

Rob.

Re: What is this doing?

Posted: Thu Apr 07, 2011 10:16 am
by spacebiscuit
This is another example:

Code: Select all

$sql = $this->getInsertQuery();
$sql is obviously a sql query
getInsertQuery is a function which I guess executes the query

but what is the purpose of:

Code: Select all

$this->
Why not:

Code: Select all

$sql = getInsertQuery();

Re: What is this doing?

Posted: Thu Apr 07, 2011 11:25 am
by social_experiment

Code: Select all

$sql = $this->getInsertQuery();
$this-> is the way to refer to the classes' methods / properties inside the class (or other classes extending it).

Code: Select all

$sql = getInsertQuery();
Will not work because you cannot refer to the method (getInsertQuery()) in that manner inside the class.
robburne wrote:$sql is obviously a sql query
It's actually a variable containing probably a value (or resource, depending on the function) returned by getInsertQuery()