conditionaly including classes/functions
| From: | Andrew Warner | Date: | Thu, 04 Apr 2002 17:28:42 +0000 |
| Subject: | conditionaly including classes/functions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-91735@lists.php.net to get a copy of this message | ||
Is it okay practice to condtionally include php files that contain only classes or functions (as opposed to just straight code)? The result is a class or function inserted right in the middle of an if{} block:
} elseif ($var=='a')
{
include('temp.php');
$obj = new foo;
echo $obj->hello();
}
The above code expanded looks like this (below). Works, but it seems wierd to be able to have a class in the middle of an if{} code block.
} elseif ($var=='a')
class foo
{
function hello()
{
return "Hello";}
}
$obj = new foo;
echo $obj->hello();
}
Andrew