Notices..your opinions

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
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Notices..your opinions

Post 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?
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: Notices..your opinions

Post 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
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Notices..your opinions

Post 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.
Post Reply