Is my PHP code object oriented?

2019-06-21 06:23发布

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 ?

标签: php oop
5条回答
Summer. ? 凉城
2楼-- · 2019-06-21 06:34

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楼-- · 2019-06-21 06:41

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.

查看更多
Evening l夕情丶
4楼-- · 2019-06-21 06:44

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.

查看更多
混吃等死
5楼-- · 2019-06-21 06:49

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).

查看更多
聊天终结者
6楼-- · 2019-06-21 06:59

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

查看更多
登录 后发表回答