Page 1 of 1

Notices..your opinions

Posted: Tue May 27, 2008 6:58 am
by panic!
The lead dev where I work wants all sites to work at error_reporting e_all without any errors which includes notices.

I find this annoying as I am having to wrap loads of things in if statements all the time.

for example

if $cat->age isn't set this will throw up a notice

Code: Select all

 
 
if($cat->age > 10)
{
print "old cat";
}
 
 
so i'm having to do something like this

Code: Select all

 
if(isset($age->age)){
if($cat->age > 10)
{
print "old cat";
}
}
 
is this a case of being being a bad coder and trying to access values of unset variables or so you think notices are overkill?

Re: Notices..your opinions

Posted: Tue May 27, 2008 7:19 am
by N1gel
You could do this. It will save you a few lines of code.

Code: Select all

 
if(isset($age->age) && $cat->age > 10)
{
    print "old cat";
}
 
If the first expression in the if fails it won't check the second so won't give an error notice.

In regards to principles, sorry I agree with your lead dev I prefer a site to work without giving any errors including notices

Re: Notices..your opinions

Posted: Tue May 27, 2008 7:30 am
by panic!
what about for
<?=$cat->age;?>
should I use
<? if(isset($cat->age)) { print $cat->age } ?>
It just seems very ugly especially when in the 'view' stage of MVC it's nice to minimise logic.

It would seem a bit too much work to assign every variable manually at the controller stage especially when we're trying to promote 'convention over configuration'. I.E activerecord style DAOs.