You are here: Re: Returning NULL vs. returning FALSE « PHP Programming Language « IT news, forums, messages
Re: Returning NULL vs. returning FALSE

Posted by Dana Cartwright on 11/22/05 08:44

From: "Thomas Mlynarczyk" <blue_elephant55@hotmail.com>
Newsgroups: comp.lang.php
Sent: Monday, November 21, 2005 11:31 AM
Subject: Re: Returning NULL vs. returning FALSE


> Yes, but I meant a situation where an "error" can be handled easily by the
> calling function, like "Call function to get some data from a file, but if
> the specified file doesn't exist (function returns error), use some
> default
> instead." (The case of a function returning a default value was mentioned
> earlier in this thread, but assuming the function can be called for
> reading
> files in different contexts, each requiring its own "default values", then
> the function cannot return a default value as it doesn't know from which
> context it is called.)
>

Well, in that case, why don't you pass a suitable default value as a
parameter to the function? Then it either returns a good value, or it
returns the default that you've supplied to it. You can then of course
supply different defaults in different contexts.

Done right, you might not ever have to test the result of the function, as
it *always* returns something that you can use.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация