syntax for importing packages

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

syntax for importing packages

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

huh?
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

what happened? :roll:
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

What's your question? Please try to ask again :wink:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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" ;)
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post 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.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Yeah, include is like actually putting one file into another.
Post Reply