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
gautamz07
Forum Contributor
Posts: 331 Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 » Thu Dec 04, 2014 2:13 am
check out this display function guys :
Code: Select all
public function display()
{
echo "<p>Book: $this->_title ($this->_pageCount pages)</p>";
}
now have a closer look at the echo statement :
echo "<p>Book: $this->_title ($this->_pageCount pages)</p>";
Why has the coder chosen to leave :
outside the brackets while putting :
inside brackets .
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Thu Dec 04, 2014 6:38 am
Because that's how the output is meant to be formatted?
[text]Book: Moby Dick (635 pages)[/text]
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Dec 05, 2014 10:59 am
Yeah - the parentheses do absolutely nothing in PHP-land. The parentheses are entirely meant simply to be output as parentheses.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
gautamz07
Forum Contributor
Posts: 331 Joined: Wed May 14, 2014 12:18 pm
Post
by gautamz07 » Sun Dec 07, 2014 11:02 pm
Thanks Guys ! Perfect !!
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Dec 08, 2014 11:30 am
gautamz07 wrote: check out this display function guys :
Code: Select all
public function display()
{
echo "<p>Book: $this->_title ($this->_pageCount pages)</p>";
}
I would recommend always using braces for object properties and array elements within double-quoted strings:
Code: Select all
public function display()
{
echo "<p>Book: {$this->_title} ({$this->_pageCount} pages) also {$arr[0]}</p>";
}Using braces eliminates any possible parsing ambiguities and would make it clear here what the programmer intended.
(#10850)