Re: [PHP] OO purism sucks - sell me on PHP5?
I'm kind of coming from the outside here, so forgive my ignorance on some matters. I have some OO experience, just not with PHP and have only worked with PHP4 so again.. kind of on the outside of all this. Rasmus, you make a great point here. OO is structured and is all about constraints whereas PHP tends to be rather flexible. So OO in PHP doesn't mean that it should comprompise the idea of a structured development method. It's just part of PHP's philosophy of allowing developers to choose their method of skinning the proverbial cat. It seems that one of Jochem's main complaints about it isn't so much the rules and structure, but the idea that he was told his code was wrong and he needed to redo a good chunk of his 2 years worth of development (or any of this code) to PHP5's OO standard then a short time later he's told that someone else had the same problem and the 'standard' was changed to accomodate. But hey.. stuff happens. Sometimes concessions need to eventually be made when there's no other way. So that leads me to the 'sell' part of my altered subject line. Rasmus said: People are not upgrading to PHP 5 because PHP 4 works just fine for them and they haven't yet discovered things like SimpleXML and some of the other killer features of PHP 5. So I've read some of the new features on PHP5 and am still not sold on upgrading. As was stated, what we've developed so far works great and there's no real incentive to upgrade. But upgrades are inevitable so in the interest of planning for the future, I'm looking at PHP5. Our XML routines work fine, but since you mentioned SimpleXML, I'll take a closer look at it. What are some of the other killer features of PHP5 that I may be sleeping on here. If it ain't broke, don't fix it works for a while, but if there are easier and/or better ways to do things in PHP5, I want in! So someone sell me on this from the point of view of someone who's upgraded and has learned the joys of PHP5. So far what I've found online has been little more than a list of new features without an idea of how much of a headache they're going to save me in the future. Thanks! -TG = = = Original message = = = Jochem Maas wrote: I understand the point you made below - you have made this argument before and I, for one, accepted it as valid when I first read the discussion on internals - which is why I avoided ranting about that (and changes like it) But you didn't avoid it, you used it as an example to back up your rant. And on the OO side your argument gets shaky as well. The whole point of OO is to add a very structured layer on top of your code to make it more consistent and more maintainable than the equivalent procedural code. There is nothing you can do in OO that you can't do with completely freeform procedural code. When you choose to go OO, you choose a set of rules and a certain code structure that by definition is going to be somewhat constrained. The argument over exactly how constrained this should be and where we should loosen things up will continue until the end of time. PPP and Interfaces are all about constraints. They serve no practical purpose whatsoever other than to add constraints. And saying that these OO issues is slowing down PHP 5 uptake is a bit of a red herring. We are competing against ourselves. PHP 4 works extremely well. There is a lot of code written for it and it works. I seriously doubt very many people are not upgrading to PHP 5 because of some debatable edge-case OO thing. People are not upgrading to PHP 5 because PHP 4 works just fine for them and they haven't yet discovered things like SimpleXML and some of the other killer features of PHP 5. -Rasmus ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO purism sucks - sell me on PHP5?
[EMAIL PROTECTED] wrote: If it ain't broke, don't fix it works for a while, but if there are easier and/or better ways to do things in PHP5, I want in! So someone sell me on this from the point of view of someone who's upgraded and has learned the joys of PHP5. So far what I've found online has been little more than a list of new features without an idea of how much of a headache they're going to save me in the future. To me the main user-visible benefits of going to PHP 5 are (ignoring the OO changes for now): 1. Simplexml eg. One-line RSS parser (of Flickr's upload queue feed) $url = 'http://www.flickr.com/services/feeds/photos_public.gne'; foreach(simplexml_load_file($url)-entry as $it) echo $it-content; 2. Much improved DOM support eg. various things you can do to a DOM // First, load your XML document into a DOM $dom = domdocument::load('test.xml'); // Apply a stylesheet to the dom $proc = new xsltProcessor; $proc-importStyleSheet($domxsl); echo $proc-transformToXML($dom); // xpath query on the dom $ctx = new domXPath($dom); $result = $ctx-query('/top/[EMAIL PROTECTED] 3]/foo/text()'); foreach($result as $node) { echo $node-nodeValue; } // pull it into simplexml and access it $s = simplexml_import_dom($dom); echo $s-child[0]-foo; 3. xmlreader/xmlwriter eg. SAX document validation using xmlreader $reader = new XMLReader(); $reader-open('test.xml'); $reader-setParserProperty(XMLReader::VALIDATE, true); while($reader-read()); echo $reader-isValid(); 4. PDO eg. Prepare execute against MySQL with named parameters $pdo = new PDO('mysql:dbname=testdb'); $sql = 'SELECT name, colour, calories FROM fruit WHERE calories :calories AND colour = :colour'; $prep = $pdo-prepare($sql); $prep-execute(array(':calories' = 150, ':colour' = 'red')); $red = $prep-fetchAll(); 5. SOAP eg. Exposing your PHP code as a SOAP web service function Add($x,$y) { return $x+$y; } $server = new SoapServer(null,array('uri'=http://test-uri/;)); $server-addFunction(Add); $server-handle(); 6. SPL eg. Iterating over entries in a directory $dir = new DirectoryIterator('.'); foreach($dir as $ent) echo $ent; 7. Filter eg. Define a default filter and use form input safely without cluttering up your code with htmlspecialchars() calls everywhere and provide easily auditable access to the unfiltered data php.ini: filter.default = special_chars echo $_POST['data']; $raw = input_get(INPUT_POST,'data', FILTER_UNSAFE_RAW); 8. Native Date/Time mechanism Date/time functions now behave exactly the same way on every platform regardless of the differences in locales if you choose to use the native mechanism. Beyond that the compiler produces smaller opcode arrays and the executor is faster. Not a directly visible thing, and this is still improving, but definitely a plus. Note that for all of this I am referring to PHP 5.1.x, not 5.0.x. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO purism sucks - sell me on PHP5?
At 9:00 AM -0700 6/2/06, Rasmus Lerdorf wrote: [EMAIL PROTECTED] wrote: -snip- (a bunch of things over my head) Note that for all of this I am referring to PHP 5.1.x, not 5.0.x. -Rasmus Damn -- remind me to never disagree with you (as if I could). My self-perceived position on the food chain just declined considerably. Any more display of knowledge like this, and I'll be back to programming with rocks. Thanks for your insight. tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Try XMLWriter ... was Re: [PHP] OO purism sucks - sell me on PHP5?
[EMAIL PROTECTED] wrote: What are some of the other killer features of PHP5 that I may be sleeping on here. You have got to get your hands on XMLWriter. I don't write any XHTML inside php any more. I've wrapped the XMLWriter object inside my own object and now I can create 100% properly escaped XHTML without ever using a '' or '' symbol: ?php $XML = new XTag('a', 'href', $href, 'title', 'This is a test such.'); $XML-push('img', 'src', $img_src, 'width', 100, 'height', 50, 'border', 0); $XML-pop(2); // img, a print $XML-toXML(); // outputs: a href=[$href value here] title=This is a test amp; such.img src=[$img_src value here] width=100 height=50 border=0//a ? XMLWriter handles: * the escaping of characters to ensure I'm writing XHTML compliant code, * tags are guaranteed to open and close in the proper nested order, * content is encoded with UTF-8 encoding, * indentation of XHTML is optional * php code is legible without needing to backslash double and single quotes * PECL version of XMLWriter (gonna be in 5.2) contains ability to write raw (unescaped content) into your xml so you can merge already-created snippets of XHTML into your XHTML. * good for creating syntax valid XHTML 1.0+ strict output * good for creating syntax valid XML documents There are a couple other 'gotta have' features of 5.1+ that are cool ... like PDO etc. Sadly, all that is cool appears to be cutting edge and so documentation and examples are seriously lacking. I find myself reading the source of many extensions just to try to figure out how to use them. Maybe that's a sign I'm upgrading too often? Of course, everyone is using 5.1.4 with XMLWriter from PECL, right? Dante -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO purism sucks - sell me on PHP5?
tedd wrote: At 9:00 AM -0700 6/2/06, Rasmus Lerdorf wrote: [EMAIL PROTECTED] wrote: -snip- (a bunch of things over my head) I thought I kept the examples pretty simple actually. If you have specific questions on them I would be happy to explain them in more detail. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OO purism sucks - sell me on PHP5?
At 10:51 AM -0700 6/2/06, Rasmus Lerdorf wrote: tedd wrote: At 9:00 AM -0700 6/2/06, Rasmus Lerdorf wrote: [EMAIL PROTECTED] wrote: -snip- (a bunch of things over my head) I thought I kept the examples pretty simple actually. If you have specific questions on them I would be happy to explain them in more detail. -Rasmus -Rasmus: Simple/Difficult are relative terms -- thanks very much for your kind offer, but I think it will be a while before I rise to that level of confusion. However, I did cut/paste your eight points into The things I want to learn category of my note pad. In defense of my ignorance, I balance what I want to learn with what I need to learn -- as demand prompts, I adjust and learn accordingly. Nothing you mentioned was completely foreign to me, just don't test me on it. :-) You see, and no offense meant, but this isn't my first time at the dance and I've seen too many times where people rush in to learn the new dance step only to find it was a passing fad and soon replaced with something kewler. So for now, I'll stay with my tried and true box-step and try not forget the reason why we're at the dance in the first place. :-) tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] OO purism sucks - sell me on PHP5?
-Original Message- From: tedd [mailto:[EMAIL PROTECTED] Sent: Friday, June 02, 2006 3:11 PM To: Rasmus Lerdorf; tedd Cc: php-general@lists.php.net Subject: Re: [PHP] OO purism sucks - sell me on PHP5? SNIP So for now, I'll stay with my tried and true box-step and try not forget the reason why we're at the dance in the first place. :-) To hold up the wall and snack upon the foods provided? tedd -- -- -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php