Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJason S
16,247 Points$mail->send vs $mail->send()
Hi i always have trouble mixing up methods and properties and variables I recall Randy saying in an object's context, a variable is like a property or something and a method is something else?
3 Answers
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsHi Jason,
In the context of an object yes.
Made this example which may help:
<?php
class mail
{
public function send()
{
echo "Send method";
}
public $send = "<br/> Send property";
}
$mail = new mail; // creates a new instance of the mail class and stores it in $mail. $mail is now an object
$mail->send(); // calls the send method on the $mail object which echos "Send method"
echo $mail->send; // echos the send property of $mail object
$mail->send = "<br/> New send property"; // changes the send property of $mail object
echo $mail->send; // echos the new send property
?>
This is one of those things that is hard to get your head around but it will just 'click' one day and start making sense.
It's probably a bad idea to give both a property and method the same name though, it will only lead to confusion.
Hope this helps :)
James Anwyl
Full Stack JavaScript Techdegree Graduate 49,960 PointsObjects have properties and methods. Properties are like variables, methods are like functions.
Hope this helps :)
Jason S
16,247 Pointsso send() is a method and send is a property?
abdi ali
10,920 Pointsyup