Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extending a class from an include file

Status
Not open for further replies.

jms8142

IS-IT--Management
Dec 3, 2001
16
US
Does any know of any issues with extending a class from an include file?

i have:

include("include.inc");

class groupadmin extends groups {
function __construct() {
print "In groupsadmin constructor\n";
}
}

$obj = new groupadmin();

the groups class is in the include.inc file. When i run this I get

Fatal error: Class 'groupadmin' not found in C:\apache\htdocs\portal\admin\usergroupadmin.php on line 14

when i paste the contents of include.inc in the file it works fine.

 
I don't know. Given:

[tt]test_class_include.inc:[/tt]
Code:
<?php

class foo
{
	function __construct ()
	{
		print 'in base constructor';
	}
}

?>

and

[tt]test_class_include.php:[/tt]
Code:
<?php

include ('test_class_include.inc');

class bar extends foo
{
	function __construct ()
	{
		print 'In derived constructor';
	}
}


$a = new foo();
$b = new bar();

If I point my browser to test_class_include.php, I get no errors.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Just a wild stab, you are using php5 I presume as the construct ( ) is obviously specific to that.

there was no path given to the file so i guess they are in the same directory?

err... that me i think

Age is a consequence of experience
 
in answer to litton1, yes, it is in the same directory.

Strange, so when i tried sleipnir214's test code, adding

class foo
{
function __construct ()
{
print 'in base constructor';
}
}

to my include file and

class bar extends foo
{
function __construct ()
{
print 'In derived constructor';
}
}


$a = new foo();
$b = new bar();

to the file i'm running, i get:

in base constructor
Fatal error: Class 'bar' not found

so it gets the included class, just has a problem extending from it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top