RE: [PHP] conditionally including classes/functions

2002-04-05 Thread Rick Emery

It's okay to do so.  That's why include() was created; to provide
conditional inclusion.

-Original Message-
From: Andrew Warner [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 04, 2002 11:29 AM
To: [EMAIL PROTECTED]
Subject: [PHP] conditionaly including classes/functions


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

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

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




Re: [PHP] conditionally including classes/functions

2002-04-05 Thread Hugh Bothwell

 -Original Message-
 From: Andrew Warner [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, April 04, 2002 11:29 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] conditionaly including classes/functions

 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:


I would find it much more useful to do something like
a transparent include-on-first-use; for a function this
shouldn't be too hard, but I have no idea how to make it
work for a class short of wrapping every method
independantly.

function MyLazy($a) {
if (!function_exists(contentsMyLazy))
include(contentsmylazy.php);// define the function

return contentsMyLazy($a);
}



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