To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-06-2004, 02:18 AM   #1
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
My implementation of import

This is how i implemented import and namespaces in PHP. obviously this is *very* limited, as its not part of the language, but it does provide a simple way of organizing classes. Now if you were really tricky and were using PHP 5 (as i am), you could mess with your naming sceme and __autoload() to get the same results with one less user-typed function call, but i think import looks cooler .

In any case, i know it may seem kind of boring, but after reading a post about something like this implemented in the engine, i decided to write it to be as extensible as possible (set the first param to false and you have 3 init options: base directory, namespace delimeter character, and error out level (that's some code ripped from the token_name() user notes)).

enjoy another pointless piece of code by Moonglobe

[edit]Forgot a few things, and also added support for single file inclusion without a one-file directory. here's what i forgot to say:

if any of the included files spit anything out, then the function checks if there is "error" (case-insensitive) in the text. if so, it lets it show up, if not, it cuts it (this is because im often too lazy to take out the debugging code at the bottom of my class definition scripts ). Also now, if there's not a directory that matches the namespace, the last namespace has '.php' tacked on and there's a check to see if that file exists. This functionality is turned off by default though, you have to pass true to the 5th param during init to get that operational.[/edit]
Attached Files
File Type: txt importshow.txt (4.2 KB, 98 views)
__________________
there's no place i can be, since i found serenity.

Last edited by Moonglobe; 02-06-2004 at 02:38 AM.
Moonglobe is offline   Reply With Quote
Old 02-06-2004, 06:24 AM   #2
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
I'm gonna have to have a look at this, might be better than what I'm bashing on; er... usage dox? Comments? v5.2?
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 02-06-2004, 11:31 AM   #3
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
haha sorry, that'sonly the do_nothing( function. there are a lot of bug fixes im putting in right now (i messed up my error code, and the single file stuff totally wrecked everything else). I'll post docs and a fixed, commented version up later today.
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 02-06-2004, 03:02 PM   #4
drawmack
Computers can do that?
 
drawmack's Avatar
 
Join Date: Apr 2003
Location: Pocono Mtns PA
Posts: 3,268
Re: My implementation of import

Quote:
Originally posted by Moonglobe
this is because im often too lazy to take out the debugging code at the bottom of my class definition scripts
you should work with assertions cause they can be gloabally turned off by setting a constant.
drawmack is offline   Reply With Quote
Old 02-06-2004, 07:32 PM   #5
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
drawmack, perhaps you could explain that for me. i've never quite got around the assert() statement and what it does...

Or just point me at a link... and not the manual i've read that almost cover-to-cover twice.
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 02-07-2004, 12:11 AM   #6
Weedpacket
Custom User Title™
 
Weedpacket's Avatar
 
Join Date: Aug 2002
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,128
Quote:
Originally posted by Moonglobe
haha sorry, that'sonly the do_nothing() function.
Jest proving I read it . I've got a pile of functions I'm slowly plugging away at (interrelated selections of RNGs, random distributions, statistical functions, and special functions) and having a smarter namespace mechanism might come in handy.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Weedpacket is offline   Reply With Quote
Old 02-09-2004, 01:26 AM   #7
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
ok so here's what i hope to be a working version... still not enough commenting, but it will get there
Attached Files
File Type: txt importshow.txt (6.3 KB, 79 views)
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:13 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.