Taking the Sting Out of PHP 5 Programming
bfioca writes "Where are the all-in-one PHP frameworks that make building well-factored and maintainable applications as easy as building simple sites? O'Reilly ONLamp's recent article Simplify PHP Development with WASP shows how to make a simple database-backed site with WASP in just a few lines of code. Other PHP 5 frameworks such as symfony and PRADO have been getting a lot of recent attention as well."
I don't claim to be a web architecture guru, but what's wrong with Drupal? Open source, PHP 5-friendly, and does everything from vanity sites to corporate sites.
--R.J.
Electric-Escape.net
The best way to take the *sting* out of PhP is to use Ruby or Python.
Give me a break, depending on such things is terribly bad for maintainable code. Exactly the opposite of the billing given above. Will code written with it be compatible with PHP 6? How long after PHP 6's release will such tools be made compatible? If you need tools to simplify php coding, you might as well just forget it.
If you want a quality product, there are no shortcuts. There is no such thing as a free lunch.
A big thumbsdown on this kind of crap. "Sting" to PHP 5 programming? Get real.
For the rest of us hip hop inclined programmers, there is PHP using HOOD (Hizous Object Oriented Development) in case you get tired of the WASP crowd.
JASPF (Just another silly PHP framework)
If you are looking for quick app development and you aren't joe home user making a website you are going to need something thats based off a model -> view -> controller architecture. Symphony does this, so does the cake framework.
"We're all mad here." --Cheshire Cat
PEAR and the new eZ components http://ez.no/community/news/ez_components_1_0_rele ase_candidate_1
I want to make some original PHP apps on my websites but I still don't know PHP. So it would be great to have some GUI application or something that let's me realize a PHP/MySQL application just out of a database model that I would draw and some specific actions specified. So I am checking these solutions out, and if someone has more solutions for me that would be great.
And don't forget SNOOP (SNoop Object Oriented PHP) for the rest of the hip house crowd who doesn't like the Country WASP crowd.
Taking shortcuts is just a bad idea. At my company we call shortcuts being 'lazy'. Just do it right without trying to lean on somthing else to help you out. It is just a couple more { and } to make your code work for soon-to-be versions of PHP without this garbage. Also, what is this 'sting'? Find it hard to use some OOP? If that 'stings' you then maybe you should not be coding in PHP. Moral of the story: being lazy will produce bad code that needs to be delt with in later versions of PHP. Save yourself the time now.
Maybe something like http://developers.slashdot.org/article.pl?sid=02/1 2/19/1740205&tid=156 mentionened on /. would appeal to you, although I wouldn't recommend it (well, people like me usually get to rewrite stuff like it)
I'm still trying to figure out what people mean by 'social skills' here.
If you simply want a site with some 0815 stuff (like a Guestbook, News, Articles, Photogallerie) use PHP-Nuke and try to create you're own template (or ask a friend to do it for free).
;-)
:D
If you want to create anything else (like a corporate site with support system [ticketbased], shop [enduser and reseller], productinfo,... or a browserbased) do it yourself or have a company done it
And if you really want to stick to a framework - create your own framework
Sebastian (using his very own framework AdvFW2 v0.3.9 since 2 years [but it's php4-based because I use it for projects I do for friends for free])
Sting has had his finger in entirely too many pies since The Police broke up...
Oh that's really easy, anyone with a clue for code can tell you that one. Can you say "Use XML"? I knew you could....
What company do you work for? If you were writing an enterprise Java application, for example, would you call using Spring or Hibernate "lazy"? Also, what makes you think that this code isn't forward-compatible? It's just a few files of normal PHP code, automatically generated from XML manifests, from what I gather. Finally, what makes you think they even need the code to work in the next iteration of the language interpreter? If they're a contractor that gets paid and bails before anything breaks, then using even the shoddiest frameworks will indeed "Save yourself the time now."
I remember a time when PHP was the next latest and greatest thing. Then MySQL tied into it which made it all the more better. Lately, however, a lot of programmers have moved onto Ruby on Rails. It almost seems like magic at the speed at which you can make useful stuff.
So portscans of my Macs prove there are many Mac exploits? Drupal has had just a few very specific security issues, just like any other internet-based app. There are many thousands of drupal-based sites, so evil-doers have written scripts to hunt down and take advantage of those that haven't upgraded. Nothing here uncommon to any other system. My drupal referrer logs fill with thousands to requests for IIS-specific files, yet I've never run a site on Windows.
Developers: We can use your help.
Complicated? I didn't realize that complicated frameworks were the pinnacle of modern software development. Here's a newsflash: PHP is popular not because of its rigid structure, nor the availability of misguided "frameworks", but because it allows people to solve problems in a flexible way with little overhead. Yes, a lot of people take it too far in this direction and turn their code into a disaster area, but others manage to build maintainable, useful apps without obsessing over whether or not their program fits into a particular "model". In addition, future maintainers of these apps won't have to read manuals about how to use the framework of the day to make changes. Strict interpretations of pseudo-standards or the use of mind-bending frameworks do not help to develop applications faster, or even better.
I wonder how many "enterprise-class" applications fall flat on their faces because the frameworks on which they are built are not flexible enough to support what their users really need. I know it's happened where I work, and the answer "oh, the framework doesn't support that" led to the success of other projects that came out of nowhere and took hold because they met the demands of users as opposed to the technical demands of project managers. In the real world, a simple PHP app may very well push an "enterprise-class" and "three-tier" monolith out of its way if it does what the users want.
LOL... You actually bothered to learn all those horribly inconsistent functions? is_null, isset? strtolower, hex2bin? strip_tags, stripslashes? strpos($haystack, $needle), preg_match($needle, $haystack)? Or are you accepting that looking at the docs every half an hour is normal?
PHP has a lot of shortcomings, and it's a shame that it's been marketed so well that people like you are so used to it that you can't be bothered to learn anything better. Will you still say how good PHP is when you've looked at the docs for the hundredth time, or tried to use Unicode, or use the wrong function? I doubt it.
To anyone else out there: PHP sucks. It has inconsistent function naming, no namespaces, far too many functions, next-to-no unicode support, catering to the lowest common denominator (who aren't expected to know how to escape a string (magic quotes) or use the query string arrays (register_globals (now deprecated, good))). Perl, Python and Ruby have none of these shortcomings. Learn something else - you'll appreciate it.
Zope is supposed to be some great product. But, when I do a search for Zope on dice.com, I might get one hit.
I get the feeling these php frameworks might be even more obscure.
Now, compare that to a product like ColdFusion.
I don't use any of those products. But, I've got to wonder.
The thing about Ruby: it's so easy to learn. I'd say you could take some schmoe with experience in functional and OOP languages (Smalltalk, Lisp+Java, any other combination), and train them for Ruby development in two days.
I have my own framework I've used for several years now and slowly upgraded. I enjoyed writing it because it forced me to learn the principles of what all the other frameworks were doing. I couldn't understand why people wrote frameworks the way they did until I ran into the same situation. However, I made some significant apps with my framework that companies are using and I found myself writing lots of documentation on them and brushing up the comments... It would have been great if I used published and documented framework just so I wouldn't have to do the tedious stuff for other people to ever maintain it.
I tear my eyes out everytime someone calls a framework a "shortcut". Usually they follow it by "There's no substitute for good coders writing good code." The business reality is that most coders are not exceptional, and some are pretty lousy. You can spend all of your budget on human resources finding epic-quality coders (and then scratch some more to come up with their epic-salaries) or you can do what the rest of the world does-- get the best programmers they can find and afford. A framework helps un-exceptional coders write better (and more consistent/maintainable) code. This arguments seems akin to saying "forget word processors! Just get someone who can make Vi or Emacs dance and turn 'em loose." It seems to me that the evolution of software is pretty much the act of layering increasingly-smart frameworks on top of machine language to allow high quality results more accessible to more people.
This article appears to be written for fools. One of the author's examples of WASP's superiority is that this:
<li flexy:foreach="arTasks,key,task">{task[Name]} - <i>{task[Due]}</i></li>
is better than this:
<?php
$arTasks = array();
foreach ($arTasks as $key => $task)
{
?>
<li><?php echo $task['Name']; ?> - <i><?php echo $task['Due']; ?></i></li>
<?php
}
?>
Because "Already you can see one of the biggest benefits of working with WASP: no need for embedded PHP code."
Well, it might look that way, because he deliberately coded the PHP version in the messiest way possible. He could have simply done this:
<? foreach ($arTasks as $key=>$task) { echo '<li>' . $task['Name'] . '-<i>' . $task['Due'] . '</i></li>'; } ?>
The WASP sample doesn't look so much better now, does it? Not so much so that it's worth downloading some unknown framework and inheriting someone else's bugs and execution overhead and security holes?
the fact that because of all of the php-4 compliant code that it breaks, few ISPs doing web hosting services are in any hurry to upgrade because too many customers simply don't have the time to rewrite their applications to be compliant with php-5, much less take advantage of any or all of the new features.
this is hitting me hard as i'm trying to put together an xml-intensive app and am stuck using home-grown open-source XML parsing and generating packages, mostly unfinished, that won't be finished because they've been superseeded by the php5 libraries that i can't use yet.
"But remember, most lynch mobs aren't this nice." (H.Simpson)
-- Joe
Wow, you know you might be right. Maybe that's why Yahoo switched to PHP a couple years ago. hmmm
There's also the Zend Framework, to be released soon:
http://shiflett.org/archive/171
Bad security by default.
Read here.
Grundgesetz * 23. Mai 1949 - 30. November 2007 - http://www.vorratsdatenspeicherung.de/
Molins is a framework for PHP5, inspired in Struts, but also it have a lot of features of other sub-projects of Jakarta, like Torque or Commons (FileUpload, etc). Integration with Smarty, and classes for logging, testing, etc. It's 200% object oriented. Come, take a look at http://sourceforge.net/projects/molins/ ;)
bet0x
PHP coders really needs some framework. Because I don't realize how else they can work with the "technology"-like thingy which has bad recursion, lots of not-thread-safe stuff, poor OO, hell slow interpreter, no namespaces, non-standard date format, 4x more built-in functions than Perl (however the functionality of them just same), inconsequent function naming convention and no unicode so far. For those who dislikes Python and likes PHP, I would like to offer one experiment. Please do the simple task: make array of arrays of dict of dict of array of dicts structure (you may feel free to make it slightly other) and then try to change/replace/remove/add and compare each element of any place. Afterall compare perfomance and readability of the code.
Don't for PHP Livepipe!
It's a PHP5 framework for web developers that was recently released and looks promising.
http://livepipe.net/
http://www.cakephp.org/
check its Object class implementation... for php4
I've found that the best way to build a framework is to figure out the style of the company/organization in question, and then slowly build up a framework that fits over time. And, don't make your code married to the framework, just date it. Leave ways to code around it if it does not fit a particular situation.
// HTML
// HTML
// HTML ....
For example, here is a simple set of functions to format a typical data entry form with title on the left side and input box/item on the right. If you want to code HTML directly instead of use the helper functions, you can. Thus, you get a shortcut, but not one that is forced on you.
formHeading("My Sample Form", formName)
rowStart("Name")
{input type=text name="myname"}
rowEnd()
rowStart("Date")
{input type=text name="mydate"}
rowEnd("format mm/dd/yyyy")
rowStart("Category")
{select name="mycat"}
formFooter(...)
(Curly braces used instead of angle braces (HTML)here to avoid slashdot edit conflicts.)
Table-ized A.I.
I know PHP has matured as a technology when people feel it's painful to use.
I realize that programming languages are supposed to be painful, but for me, PHP 3 made programming fun again. As a sysadmin sort it was remarkable to be coding and enjoying it. This seemed to be true no matter whether it was a 10-line hack to get something done on a website, or a top-down structured project.
And you know when then turnaround happened? When PHP stopped being fun? I have an opinion. I think it coincided with the discovery that global variables were found to be harmful. Suddenly this thing which had so much instinctive power, required the use a system array with a specific syntax.
Why do they always have to go with `simple' example?? Why not go into some depth and show a moderately big project with some complex feature implementation?
Frameworks are fantastic beasts. I fear them yet I adore them at the same time. I do this with anything that I didn't write. Indeed, I moreso do this with anything that I do write!
To the point: I see a lot of people bashing the concept of frameworks and stating that you shouldn't use frameworks because it's just being lazy or that frameworks are a bad thing. I believe this negativity comes from inexperience and ignorance.
I agree, these are biting words, but consider the fact that the arguments used to support these ideas are based on incorrect assumptions and false information: thusly revealing that they know nothing about the framework(s) nor have they used them. (Either that, or they've used them incorrectly, producing a negative response! Try brushing your teeth with a hacksaw!)
Goals of various frameworks are many, with each framework focusing on something completely different. I'll consider the framework that I am currently in the process of developing as an example: this framework's goal is to provide a semi-rigid structure for web application development, with particular emphasis on separating executive logic, data logic, and interface logic. (For anyone that doesn't know right off, this is the MVC pattern.) I chose this pattern simply because it suited how I like to develop my programs and gives me the amount of flexibility I need to provide for easy ways to quickly develop and make changes, to work with teams, and to better see how my code is interacting with the flow of the program. What happens with something doesn't work? Well, I pinpoint what type of error is ocurring, then I can cut out two-thirds of the code (granted, very little code is required for the model to actually work).
I read a number of comments ago that PHP was designed without a rigid structure to provide for rapid development and flexibility. The commentor is absolutely correct, but it wasn't designed to disallow structure completely. In fact, with the blank canvas that PHP does provide, it certainly welcomes all attempts at structuring code. This is evident in its (newly-revamped) support for object oriented design as well as even basic support of functions.
Another argument that I heard levied against frameworks is that they sometimes don't support certain functionality. There are two responses for this: firstly, not every solution is perfect; secondly, some frameworks are poorly designed. Of course, the second point is just that and requires no further exploration. However, the first point must be clarified. Certainly, we all agree that there are no perfect solutions, but doesn't this seem a bit like a copout? I don't believe so: I believe that limitations from using a well-designed framework stem from a lack of understanding its design or from not having enough creative foresight to know how to use it effectively. At this point, I seriously have to ask you if this framework suites what you're trying to do.
Honestly, not every website will benefit form a framework. You have to realize this. Don't use the framework for more or less than it's intended for.
One last address: for those that think that using a framework inherently means added complexity, sometimes you're right. However, you must realize that some more complexly designed websites with intricate functionality (to a safe degree) could benefit from using frameworks just as you can benefit from using standard functions for writing quick scripts.
M.T.
"Support Bacteria - Its the only culture some people have" - Circa 1985
I know a bit of PHP but I can't think of enough content that would justify anything more than a straight html site.
(and I don't like other people's ideas either!)
Let me get this right..
You have a low-enough UID to supposedly be somewhat knowledgeable, yet you advocate writing frameworks and not marrying the code to the framework..?
Then why the hell are you mixing the View in with the Model (and most likely Controller too?)
Honestly, it's people like you who give PHP a really bad name.
Any sane person would AT LEAST be using a templating system like Smarty.
And I don't see the magic numbers for Cake or Sympfony...which is 1.0, at least.
Besides, from the front page of the WASP sourceforge site:
Slices, dices, eats your lunch.
I'm disappointed that Slashdot editors are allowing more and more people to use /. simply as a means for self-promotion. Case in point: here we have a posting by Brian Fioca, referencing an article by Brian Fioca, which talks about a framework by Brian Fioca.
And I wonder why I'm always so surprised that people complain about bias in the media...
all i can say: WTF is this?
//my own function // again here is my own functions :)
;) so remember KISS)
Has all wise people suddenly disappeared?
Where has the philosophy of KISS disappeared? namely: Keep It Simple, Stupid!
WASP seems far from simple, let's take this example:
Request::getParameter('Add') != null
wtf? Why can't one do $_POST['Add'] != null?
What format even is Something::Something ??
TaskWrapper?
What's so bad with plain Modular Design + Smarty?
I can do easily with it after building the init scripts (transfearable from project to project) something like this with 8 lines or so.
namely
if ($_POST['Add'] != null && $_POST['Job]' != null) {
$Job = Validate($_POST['Job'], 'string');
DoQuery("INSERT INTO 'todo' VALUES('', 'Job', '" . timestamp() . "')");
}
??
Note that is untested code etc. and probably wrong
I could bet that WASP doesn't have such an good documentation too, making it harder to development.
Why do we need PEAR objects for everynew project? etc.
You can do hell of a fast code with standard PHP too, tested dozens of times that ain't even hard if you just remember KISS.
Now, i've done a browser game (http://www.paradox-online.net/ ) with PHP, also i'm working on a framework (http://framework.artichost.net/ ) and game will be using it in future as the basis. So i know what i'm talking about.
Now, could someone make me see the PRO side of using WASP for example?
In my eyes, all WASP does is adds complexity, which NEVER is good. You need to KISS it, make it easy to maintain, easy to debug, easy to read etc.
You have to work on some massive things before you realize that, complexity ain't the way to go. (My browser game, over 14k lines of PHP code initially... cutting it down a lot at this dev period on it, while increasing features... all thanks to KISS philosophy... Oh yeah, you can cut most loops of queries straight at the MySQL query, making your code even shorter and more fault tolerant...
Pulsed Media Seedboxes
Has it ever occured to you that Request::getParameter() could do logging, check if the variable isset() and so on and so forth? Or are you just a fucking idiot that just discovered functions and does not think ahead?
Of course PHP is somewhat quirky. We all know that. I'd also rather do all my stuff with Python, Zope and Django. But it happens to be that everything is run in PHP nowadays and lots of clients want PHP modifications or an extension to one of the 10 million PHP/MySQL CMSes out there.
Luckily there are neat tools that make professional PHP project work very easy and fun:
PHPTAL (http://phptal.motion-twin.com/) is a PHP based redoo of Zopes TAL (Template Attribute Language) - the best Templating concept ever. Makes Prado look even more sucky than it is allready.
CakePHP (www.cakephp.org/) - the PHP addition to the MVC Framework hype that Ruby on Rails kicked off. Just the right thing for larger Projects that cry for clean frameworks. Very neat.
We suffer more in our imagination than in reality. - Seneca
i'd like to knwo what people see is "so wrong" with php5? i mean, damn php6 is in alpha stages, why the hell can't people update to php5 :p
:p
almost EVERY host supports php4. only ha handle full have php5.
"we support the latest technologies... this include php4, even though php 5 had been production stable for 2 years"
i know that has nothing to do with the article, but i had to rant
Skal Tura said:
u dotayim.php
"WASP seems far from simple, let's take this example:
Request::getParameter('Add') != null
wtf? Why can't one do $_POST['Add'] != null?
What format even is Something::Something ??"
------------
Well Something::Something is simply the syntax to access a static function of a class. It is simple.
See http://www.php.net/manual/en/keyword.paamayim-nek
Either I misunderstood, but it is not like it is one of the most obscure thing in PHP to know that one.
Yeah, good point. Could even like like...
...although I prefer not to use short tags in the interest of XML compliance. (The parser will try to parse XML declaration tags.)
Uh, yes it seems normal to me after i checked that doc.
:)
:: used in PHP. and believe me when i say i've read A LOT of PHP code from many different coders & open source projects.
I've never needed something like that.
so i've used Object->Function
and yes, i would define that "obscure thing in PHP" as that was the first occurence ever i've seen
Pulsed Media Seedboxes
Yeah, I can see someone developing without ever need one. But sometime you just want to stick static variable or function to an object and that come handy.
But if you do something like this:
$o = new Object();
$c = $o->add($a,$b);
Well you instantiate the object to use a static function (considering that it is not working on the object, but just using parameter and returning a result).
Therefore doing
$c = Object::add($a, $b);
seem more logical in that scenario (or maybe use a stand-alone function).
There is probably well logical reason sometime to bind one static function to an object (beside just regrouping function at one place).
I still don't see much of a benefit on doing that, you mean that i don't need to instantiate the class to be an object? (ie. no $something = new Class;)
:)
I used a fairly complex OO orientated data structure on my browser game (something like 3-4 A4 pages long just the objects alone), and never needed anything more than more dimensions into the goddamn OO support in PHP >_ i worked around it by doing 2 different Object trees and using a pointer variable to the second one
Pulsed Media Seedboxes
Skal Tura said:
// return an array with the list of all Something // return an instance of Something or null if not found
/* setter and getter, those work on the instance directly. */ ... } ... } ... } ... } ... } ... } /* to save or delete (i.e. destroy) your object */ ... } ... } /* to retrive something (i.e. from database), I already talked about this */ ... } ... } ... } /* if you want to sort a list of something, you can use that function ... }
/* $list_of_something = array(); */ // retrieve Something with id 3, 10 and 14 // add Something with id 126
// will sort the list by the name of Something.
... but it is used staticly.
;-)
"I still don't see much of a benefit on doing that, you mean that i don't need to instantiate the class to be an object? (ie. no $something = new Class;)"
No, I may have expressed myself wrongly or it is just still unclear to you.
Actually if you call Object::someMethod(); you are just calling the method that is defined as static for the class (even if in PHP4 for example, there is no static).
In that static method, you won't be able to use thing like $this, because you are not working on an instance of the object ($this being a pointer to the instance of the object), you are just calling it.
So if you have a function that doesn't do anything on the object itself, but you want it associated with your class definition, you may use it that way.
Example that I saw is like when you want to retrieve a list of Something.
You will do:
Something::findAll();
Something::findById($id);
etc.
You could as well code a function:
find_all_something(); or something_find_all(); amd it will be the same.
Some more code (unfortunaly it doesn't look as right on slashdot preview, but you may copy it in some editor to read it better)
class Something
{
var $id;
var $name;
var $description;
.
function setId($id) {
function getId() {
function setName($id) {
function getName() {
function setDescription($id) {
function getDescription() {
.
function save() {
function delete() {
.
function findAll() {
function findById($id) {
function findByIds($ids) {
.
* to help sort the result.
* example: usort($list_of_something, array("Something", "compareByName"));
* see: http://ca.php.net/manual/en/function.usort.php
*/
function compareByName($a, $b) {
}
So you may work it out like this:
$list_of_something = Something::findByIds(array(3,10,14));
$list_of_something[] = Something::findById(126);
usort($list_of_something, array("Something", "compareByName"));
Well here you don't use Something::compareByName()
When I write this, I feel it is clean (of course it is a pretty simple case too). But I think those can be useful and clean way to use static method for a class.
Hope that help