Oliver Bayes-Shelton
Oliver Bayes-Shelton

Reputation: 6292

Is my PHP code object oriented?

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 ?

Upvotes: 5

Views: 739

Answers (5)

Tigraine
Tigraine

Reputation: 23648

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

Upvotes: 1

AieshaDot
AieshaDot

Reputation: 835

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.

Upvotes: 3

Henrik P. Hessel
Henrik P. Hessel

Reputation: 36617

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.

Upvotes: 3

rpjohnst
rpjohnst

Reputation: 1632

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

Upvotes: 0

Mez
Mez

Reputation: 24933

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.

Upvotes: 0

Related Questions