Is my PHP code object oriented?

2019-06-21 06:05发布

问题:

If I made my PHP code which would connect me to my MySQL database in a separate PHP file and made a require on the necessary pages of my website would the DB Connent PHP file be an Object Orentated item ?

回答1:

OOP is a concept. So if you include a file via the require command and this included file utilizes OOP then your script uses the concept of OOP. If not then your mainscript doesn't include it, too.



回答2:

Oliver, Check out this link about object oriented PHP. It will give you a basic intro and then you can determine if indeed your code is object oriented.



回答3:

You need to know that basically require only puts the text from the required file into the executing .php file.

So it doesn't make your code any more OOP by requiring another file, it just makes it more structured and maybe more maintainable in the future, but not OOP.

OOP would mean that you have created some sort of object that you call from now on to execute commands against. You can read more on OOP in Wikipedia

I strongly suggest you read the book "Code Complete" if you are just beginning with programming and just keep on experimenting. The road to OOP programming usually leads through lots of bad procedural programming (that's what you are most likely doing right now).



回答4:

That depends on the code in the seperate file. If it's within a class that you call, rather than just a set of functions, then yes. If not, no.



回答5:

Of course. You could also use MySQLi, which is object oriented as well.



标签: php oop