well if you find the comments i'd like to see them to see if they have something better or tighter code. i have php.net manual in a chm, but i haven't come across any namespace stuff yet.
my goal was to make something someone could easily read that could help with a naming scheme and file structure and not have to repeatedly use or worry about errors in case the class has already been called.
PHP Code:
if (! class_exists( 'myClass' )){
// include class here
}
well it might possibly help with keeping the naming without collisions because the class name should reflect the path. only downside is long class names, but an ide with autocomplete would help with that.
i have done this with constants in order to make it easier to read, plus the idea is to reuse the naming scheme as much as possible. so like Ptx or Core (whatever your root) which comes in handy if you use an ide that autocompletes constants.
core.web.ui.controls.newssearch should reflect class core_web_ui_controls_newssearch
core.web.page.newssearch should reflect class core_web_page_newssearch
but to instantiate a class you would still need to do
$x = new core_web_ui_test; or
$class = core.web.ui.test();
$x = new $class;
what i have found at php.net is that all classes, even when capitilized, are stored lowercased and you can't use anything but an identifier when naming a class or an indentifier /variable when calling a class. i know some people would hate it, but it would be cool for me to be able to use constants with dot concantination in order to form the name of the class or even something seperate from contstants just used for naming purposes.
currently i don't see how you could fully be install namespaces into php itself unless the namespaces and their files are held in memory or php was kept in a compiled state, without being depedent on the scripts for each call. but it would be cool to have,
on the bright side the above would help people to have an idea from where the class is being called from in the folder structure and that the current class/file/code is depedent on those files and where those dependant files are.
i could make a class factory for it or even extend the idea into a dispatcher, but i would probably need to place an optional array or mixed var in the signature.
as far as doing what prado does with the xml, i always worry about the overhead in php4 with xml, not to mention the fun of using sax or dom. thats the reason i nixed the idea of using ini and xml files, till i start writing for php 5 (but as i'm writing now, i'm keeping php 5 in mind and make the current scripts both php5 & php4 compatible)
but after looking at wact and xiarah (spelling?) and other frame works, including dot net (due to job). i've come to some conclusions for guidelines for myself and they are up for debate or critiquing, cause i still have a ton of learning, i've only been doing this (programming) for little over a year.
1) documentation!
make the code self documenting. including locations of dependencies (files, objects, etc) . and then create even more documentation, the php doc is great, buut... if there isn't much detail on the flow, variable types, code examples, the main idea, dependcies, default values or the values that are allowed (in cases of a switch statement or other times this is called for) and tons of file paths doing the ../../../../../../home/index.php, that makes it so much harder to read, esp with limited time.
document know issues and put them all together in a place where people can find them. i spent an hour trying to fix an exception in an application throwing a thread error in vb.net, using the response.redirect, the thing is, it always throws the error when calle, and i mean always. and there is documentation on it, but its soo obscure and oddly placed that it wasn't funny.
2) keep your code easy to read code even if means long names, even though php is loosely typed, it helps to prefix variables, and use names that would mean the same thing to everyone that would look at it and could read english.
3) stay away from pear (altogether) & php extensions that are not included with the default download of php when working on something that will be used in many different environments
4) keep your inheritance from going more than 2 deep
5) try to write your very base classes to be self containing with 0 or little dependancies.
when doing research on errorhandling, so many of those classes were tying in email functionality that should have been seperate. If you need to use that class alone, then yeah put in the bare minimum to send an email, otherwise build an email class, the error handler class and seperate master/manager class that would configure the classes and override the errorhandler's built in mail functions, with the email class's full functionality.
i know alot people don't say reinvent the wheel, but its almost easier to write something from scratch than go through someone elses code, esp if the code has more information about the author and the open source license than through the rest of it.
Off Topic:
and i'm sure that someone has already has thought about it or done this, but you can emulate code behinds and all that jazz in php if you really wanted to.
<? require_once('loadApp.php); inherit('index.class.php'); ?>
which could read the file that the the tag above is placed in, parse it, remove the php tags and then print it back out to the browser.
and i'm sure this has probably been done too, but know of anyone who serializes objects or information into the web page? i do know that session does this automatically and puts it into a tmp folder, but i'm just curious about using it to put in the page and wonder if that can be useful.
sorry didn't mean to write a book. i do appreciate your comments. but due to inflation, high gas prices, i'm sure its worth 25 cents.
Bookmarks