Page 1 of 1

syntax for importing packages

Posted: Mon Jun 25, 2007 12:42 am
by saumya
hi guys,
can you please help me out with understanding the import statement in PHP.
Currently I am doing it with "include_once" as

Code: Select all

include_once "com/saumya/controller/Controller.php";
class myClass
{
    //all the class code
}
I am not sure whether its the right way of doing things like this or not.
Please suggest.

Posted: Mon Jun 25, 2007 1:14 am
by feyd
huh?

Posted: Mon Jun 25, 2007 2:32 am
by saumya
what happened? :roll:

Posted: Mon Jun 25, 2007 2:54 am
by Oren
What's your question? Please try to ask again :wink:

Posted: Mon Jun 25, 2007 3:14 am
by Chris Corbyn
Yes, that is how PHP includes files. There's no "import" in PHP like there is in other languages because PHP has no concept of namespaces. If you include a file, you include only that file (and any files that includes within itself) rather than an entire "package" ;)

Posted: Mon Jun 25, 2007 3:49 am
by saumya
Thanks buddy.
I was confused for "include" actually includes the file inside another file.So while working OOPs in PHP its like including code of one file in all the files that include it. Unlike other languages, where import just holds a reference to the file.

Posted: Mon Jun 25, 2007 5:28 am
by superdezign
Yeah, include is like actually putting one file into another.