Jump to content

[SOLVED] php Classes in OOP


zVirx

Recommended Posts

Hello, i got a few question about OOP in php that i wasn't able to find an answer to:

 

1. When creating a class, what extension should it be saved into .php or .class ?

 

2. Should the file name of the ( .php or .class ) file be the same as the name of the class declared inside ?

 

3. Should i include() the file of the class into the current php script thats going be executed to be able to instantiate an object of it ?

 

4. Was php designed to be OO in the first place ?

 

the reason why i asked these question is that i've been programming in another language which is java ... and was trying to implement the same rules of OOP i learned there into php ( Which shouldn't be a problem since php is object oriented as well, right! )

Link to comment
https://forums.phpfreaks.com/topic/135600-solved-php-classes-in-oop/
Share on other sites

1.  I usually go with .php since the server will parse a .php file if someone finds it and directly accesses it.  A .class file will usually not be parsed.  (Unless Apache/IIS or whatever is config'd to do so.)

 

2.  Doesn't matter, but if you use some kind of naming scheme, you can use __autoload to automatically load file and not have to include/require them.  http://php.net/__autoload

 

3.  See above.  But yes, the script has to be loaded into the script in which you want to use the object.  I would probably use require_once, but include would serve the same purpose in most situations.

 

4.  No.  It originally had no OOP support, and then in PHP4, OOP was added (fairly ghetto-like) over arrays.  Then, in PHP5, OOP handling was written and made much better (faster, more features).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.