Page 1 of 1

What happens when I include files in Classes?

Posted: Thu Apr 03, 2003 7:01 pm
by Cogs
If I had a library of functions, and I included it into classname(). Would I be able to call the xyz() function of the library as if it was a function was written inside the class?

IE)

Code: Select all

<?php
class io { // I don't want to use extend
  function classname() {
     include("lib.php");
  }

  $this->xyz(); // A function of lib.php
}
?>

Posted: Thu Apr 03, 2003 7:08 pm
by volka
no, the included script lives in the scope of function classname and is gone after the function/method ends.

Posted: Thu Apr 03, 2003 7:10 pm
by Cogs
Does anyone here know a way that I can do this w/o extend?

Posted: Thu Apr 03, 2003 7:58 pm
by Sevengraff
Why don't you want to use extend?

Posted: Fri Apr 04, 2003 4:54 pm
by Cogs
The file containing xyz() does not always exist and the current class is the parent to another classes, so the external library can't be parent or child.

Posted: Fri Apr 04, 2003 6:25 pm
by volka
make it exist all the time (empty dummy-class) and the base class

Code: Select all

<html><body><pre><?php
class CA
{
	function funcA()
	{
		return true;
	}
}

class CB extends CA
{
	function funcB()
	{
		return true;
	}
}

class CC extends CB
{
	function funcC()
	{
		return true;
	}
}

print_r(get_class_methods('CC'));

?></pre></body></html>
and the trouble's history ;)