Reserved word include or "use" in PHP?

Asked

Viewed 298 times

9

I saw somewhere that word reserved include in PHP should be used only in procedural programming, and that in object-oriented programming the word reserved should be chosen use.

I haven’t found anything that would lead me to believe that the replacement is correct. That is, it is the same thing to use include or use to call other parts of the program, which would be like an import, it is not?

  • Well I used it in the program: <?php namespace site; include_once 'site/modulo1/Pessoa.php'; use site modulo1 Pessoa; use DAO Connection;

1 answer

8


That doesn’t make sense, at least not without an explanation. If you saw it somewhere and didn’t explain why, ignore it, possibly it is the person’s taste. If you have an explanation, then if you understand the basics you can assess whether it makes sense or not.

If you don’t use the include load the auxiliary files to that application in what way? Have other similar words, but does essentially the same. There are ways of automatic loading. What may be questionable is its use. And if it exists, it’s because of the structural failure of language. It has nothing to do with object orientation. Actually little of what people think about OOP really is OOP, and a lot of OO people don’t know even though they think they’re using this paradigm.

The include carries a source code, the use enables the use of a namespace. A namespace is just a way to organize codes with a surname to facilitate access and disambiguate equal names that do different things. The codes are more physical, the namespaces are more logical. Has a question on the subject in another language, but the basic idea is the same.

Even the use has to do with modularization not object-oriented.

Every time someone talks about procedural X OOP in PHP there’s a chance that the person doesn’t understand about OOP and uses it just because it’s fashionable, so she thinks that if she does procedural she’s doing something wrong, which is far from true, especially in PHP.

  • On the link http://www.diogomatheus.com.br/blog/php/understanding-namespaces-no-php/ I found something about the namespaces and I understood to use as import. However I was thinking and if you want to use only once, I know I should use include_once then? It’s just that I’m making an application with phpOO and I don’t want to get it wrong! It might be a mix of it... all. Expensive how to proceed?

  • It doesn’t matter anything, it only makes it available for use. One has nothing to do with the other, one does one thing, the other does something else, one does not replace the other. Something tells me you’ve gotten it wrong just the way you’re talking :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.