Hi all,

I've USED fucntions, i've MODIFIED functions, but to date I haven't written
much in the way of reuseable code/functions.  I'm at the point now where I
can identify what sort of code could better be controlled by a function
library, and want to get started on creating my own.

However, I'm getting snagged on the smallest things... but maybe i'm
expecting too much from PHP, or asking the wrong questions.  "return" seems
to stump me the most.  I've checked out the manual under "return" and
"returning-values", but i'm still a little blank.

I'm sure there are some tutorials out there, but can't really find any that
attack it from the angle I need, as yet.


Anyhoo, perhaps I can learn by example.  I find myself doing a lot of
include files, and have been writing this code:

<?
$file = "somedir/something.php";
if(file_exists($file))
    {
    include($file);
    }
else
    {
    echo "could not open file $file for inclusion";
    }
?>


I'm sure there's a better way, such as using or die("something");  ANYWAY,
the above code seems to me like a good candidate for a function...
something like safe_include('somedir/something.php');

So I had a go...

<?
function safe_include($file)
    {
    if(file_exists($file))
        {
        include($file);
        }
    else
        {
        echo "could not open file $file for inclusion";
        }
    }
?>

... and it worked in some instances, but did not in others (forgive me, it's
been a while since I tested it).  I'm sure return() should be used here, but
I'm not sure how/where/why to use it, or more importantly, the
purpose/reasoning behind it in comparison to "echo" etc etc.


Many many many thanks in advance, and apologies for the the long email!


Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to