[SOLVED] Help with include

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
HeavyWave
Forum Newbie
Posts: 5
Joined: Thu Mar 10, 2005 6:54 am
Contact:

[SOLVED] Help with include

Post by HeavyWave »

I just do the following:

Code: Select all

include("/conf/modules/authorize/main.php.inc"); 

$auth = new mod_authorize;
And this leads to an error, I don't know the exact message because .php file is used as a template handler, so I simply get clear-page.
Everything works without $auth = new mod_authorize;

The main.php.inc file is:

Code: Select all

<?

class mod_authorize
{
 	function show()
 	{
 		return '<h2>Hello World!</h2><br>';
 	}
}

?>
q
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

try

Code: Select all

$auth = new mod_authorize();
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

calling a class should always be followed by open and closed parantheses even if there is no parameter to be passed to the constructor.
HeavyWave
Forum Newbie
Posts: 5
Joined: Thu Mar 10, 2005 6:54 am
Contact:

Post by HeavyWave »

Code: Select all

$auth = new mod_authorize();
Doesn't help. I've made constructor. Made a testing file and now I get error: Fatal error: Cannot instantiate non-existent class: mod_authorize
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Maybe <? ?> is a prob? Try <?php ?>.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

It means that the class could not be found in the file.
why dont you post your code mate???
if you have defined the class in a separate file; make sure you include the name of the file properly in the file where you instantiate an object of the class you defined. :)
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

He doesn't seem to get include error, so the file must be ok. From what he posted, it's really difficult to find what could be wrong.
HeavyWave
Forum Newbie
Posts: 5
Joined: Thu Mar 10, 2005 6:54 am
Contact:

Post by HeavyWave »

Code: Select all

<?php

class mod_authorize
{
        function mod_authorize()
        {
                ;
        }

         function show()
         {
                 return '<h2>Hello World!</h2><br>';
         }
}

?>

Code: Select all

<?

include_once("http://antropogeon.loresit.com/conf/modules/authorize/main.php.inc");

$some = new mod_authorize();
echo $some->show();

?>
That's all code. I get error: "Fatal error: Cannot instantiate non-existent class: mod_authorize in /home/loresit/public_html/antropogeon/test.php on line 5"
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

first you don't that full path name, just a require("file.inc.php"); or whatever. second you dont do $some = new class_name(); you do

Code: Select all

$some = new class_name;
HeavyWave
Forum Newbie
Posts: 5
Joined: Thu Mar 10, 2005 6:54 am
Contact:

Post by HeavyWave »

Thank's, now it's working.
Post Reply