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!

PHP with OOP - Must I require the Class???

Status
Not open for further replies.

scripter50

IS-IT--Management
Dec 9, 2002
35
US
I have some PHP code in OOP format to maintain and upgrade. In most of the pages, an object is created using class 'block', but there is no 'require_once(block.php)' on the page and no 'include' file. How the heck does the file know where to get the class information?

Thanks,
PHP Oldie, OOP Newbie
 
Good question.
The name of the include file does not necessarily match the name of the class that is contained - you'd wish it would.
What about a quick grep for 'class block' thought the source files?
 
In this case, there is a class file named 'block.class.php' where class block is created, and objects created in other php pages like '$block1 = new block()'. But nowhere on the page is there a reference to 'block.class.php'. All of my books on oop php say 'you will not be able to create an instance of the class if the script does not have access to the class definition' - makes sense to me! I've also looked for the class included in another include file, but nothing there either. I'm stumped!
 
I can only say that the statement is true: No access to the class makes creating instances of the object impossible.
Hence, I think there must be an include or require statement somewhere.
The only scenario I can think of is that there might be something set for the auto_prepend_file value in the php.ini
php.ini said:
auto_prepend_file string

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the include() function, so include_path is used.

Maybe there is another include file that requires the class.
DId you do the grep?
 
I'm sorry, I'm not familiar with the 'grep'??? I checked the .ini file and there is nothing set in the auto-prepend.
 
What platform are you on? *NIX type or Windows?
 
I found the connection. It was three layers down in the 'require' chain. Now I can proceed. thanks DRJ478 for your assistance!

scripter50
 
You might be interested to note that PHP5 now has 'autoload' capability:
Basically, if you have a standard naming convention for your classes, then you can define one function to handle the automatic loading, and anywhere you use the class, PHP will make sure the class file is loaded. This way, you don't have to bother keeping track of a long list of files to include everywhere.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top