
Originally Posted by
jMerliN
O(n) solutions suck.
Suck hard, too.
Because it results in code like this anyway?
PHP Code:
// way we did it without ur function
$f = realpath('some_file.php');
if( in_array($f, get_included_files()) )
{
printf( "File, '%s' is included.", $f );
} else {
include( $f );
}
// way we do it with ur function
function is_included($filename)
{
return in_array( realpath($filename), get_included_files() );
}
$f = 'some_file.php';
if( is_included($f) )
{
printf( "File, '%s' is included.", $f );
} else {
include( $f );
}
When actually it could be avoided entirely using this,
PHP Code:
require_once( 'some_file.php' );
which also resembles O(n).. Shit, almost everything in PHP does.
I think in PHP that's accepted by now.