what does this line mean?

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
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

what does this line mean?

Post by ashiland »

public function Validname()
{
return !empty($this->_nom);
}

I don't understand the meaning of return !empty($this->_nom);

thanks.
karolismf
Forum Newbie
Posts: 7
Joined: Mon Jul 09, 2012 8:54 am

Re: what does this line mean?

Post by karolismf »

Your code:

Code: Select all

public function Validname()
{
return !empty($this->_nom);
}
!empty = not empty.
$this->_nom = (private $_nom; in class)
if you want a detailed explanation what $_nom does in your case give us your all class code. :)
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what does this line mean?

Post by ashiland »

Thanks, but I don't quite understand what "return !empty" means together.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: what does this line mean?

Post by pickle »

! means not.

So you're returning opposite of whether or not $this->_nom is empty. The idea being, if the variable is not empty, or !empty(), then the name must be valid, hence the function name "Validname"
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ashiland
Forum Newbie
Posts: 18
Joined: Sat Jul 16, 2011 5:19 am

Re: what does this line mean?

Post by ashiland »

Thanks for your help pickle; my problem was the hidden 'if' in the code, I didn't know that.
Thanks again.
Post Reply