What is this doing?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

What is this doing?

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: What is this doing?

Post by social_experiment »

It looks like objects are being instantiated
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: What is this doing?

Post by spacebiscuit »

More specifically what does the '->' do/mean:

$this->end_on

Thanks,

Rob.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: What is this doing?

Post 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();
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: What is this doing?

Post 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()
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply