What happens when I include files in Classes?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cogs
Forum Newbie
Posts: 17
Joined: Thu Mar 27, 2003 4:57 pm

What happens when I include files in Classes?

Post 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
}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

no, the included script lives in the scope of function classname and is gone after the function/method ends.
Cogs
Forum Newbie
Posts: 17
Joined: Thu Mar 27, 2003 4:57 pm

Post by Cogs »

Does anyone here know a way that I can do this w/o extend?
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Why don't you want to use extend?
Cogs
Forum Newbie
Posts: 17
Joined: Thu Mar 27, 2003 4:57 pm

Post 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.
Last edited by Cogs on Fri Apr 04, 2003 6:31 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;)
Post Reply