Slashdot Log In
Going Dynamic with PHP
Posted by
ScuttleMonkey
on Mon Feb 20, 2006 01:06 PM
from the not-the-bastard-child-of-languages-anymore dept.
from the not-the-bastard-child-of-languages-anymore dept.
Five-Oh writes to tell us that IBM DeveloperWorks has an interesting article about the OO advantages of PHP V's new features. From the article: "PHP V5's new object-oriented programming features have raised the level of functionality in this popular language significantly. Learn how to use the dynamic features of PHP V5 to create objects that bend to fit your needs."
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
PHP's Comeupance (Score:5, Informative)
- Class constants must be string literals and only string literals (no variables, arrays or objects).
- Type-hinting is confined to arrays and objects (feature?).
The unadorned output of phpDocumentor, PHP's analog to JavaDoc, is also suboptimal; for documenting PHP, therefore, go Doxygen [doxygen.org].Re:PHP's Comeupance (Score:5, Funny)
I must say, Sir, that I salute you for your post. Not only is in Informative, it is also well drafted in the Queens English, not in the debased language of Internetland. Furthermore, you have managed to obtain the coveted pole position of posters, so to speak. As I write this epistle of congratulations, I shall drink a toast of finest port wine to you, and I wish that your correspondence with the world shall continue for all eternity.
If I may be so bold as to trouble you with two requests, it would be these. Firstly, may I post a copy of your memorandum above the post to which I fasten my servants when I whip them for dumb insolence and/or sundry grammatical errors, including the splitting of infinitives or the use of the accursed Internet language? Secondly, my wife is expecting our first child, conceived soon after she spent a night in my servants quarters, teaching them virtue of prayer. Would it be presumptive of me to command her to name her baby (1+-sqrt(5))*(2**-1). We are unsure at present of the sex of the baby, since we have emigrated to the 19th Century to escape the linguistic slovenliness of the later epochs, but we feel that such a name would distinguish a child of either gender?
Yours, etc
Hal Porter, esq.
Parent
Re:PHP's Comeupance (Score:3, Informative)
Re:PHP's Comeupance (Score:4, Informative)
Parent
If you're going to be this generic... (Score:3, Insightful)
The answer would seem to be that there is no input validation or output interpretation going on in this sample. So, you can either write a switch block that makes sure your integers are in valid ranges, etc. or go back to individual properties. (Six dozen of one, half of the other.)
Re:If you're going to be this generic... (Score:2)
Amen. My issue with databases and all that is that they are not abstract enough. Either one must create a new table when one wishes to implement a new feature, or one must develop some extremely generic database that is hard to search. I don't think that moving toward Java is necessarily the answer.
This will be off-topic
(Six dozen of one, half of the other.)
Hahaha. That was priceless. I assume you meant, "six of one, half-dozen of the other"? It is fairly humorous, however, to say, "72 of one thing, .5
Re:If you're going to be this generic... (Score:5, Funny)
Well, you could always create a single-table database. Call the single table "Stuff," put a generic autoincrementing key on it, and give it two more columns: a type identifier and a serialized object that contains all the data.
Of course, you could also stab yourself in the eye. Might be preferable.
Parent
Experiences (Score:5, Interesting)
BUT it's still got all the crud of PHP4. For those transitioning from PHP4 objects one great feature is the new warning when using the older style of classes. However all of those things people find quirky about PHP4 still exist. For example, now you can force a function parameter to be a certain type of object, but not a basic type. You still can't even fully overload a function.
My view is that it's two steps forward and one step back. They need to consider deprecating features and making a php.ini option to not allow the use of any deprecated features.
Re:Experiences (Score:2)
How so? I'm not saying that PHP classes are fully OO, but overloading, AFAIK, is completely supported.
They need to consider deprecating features and making a php.ini option to not allow the use of any deprecated features.
If backward compatibility could be turned on and off, I'd prefer some sort of php_compatibility( COMPAT_PHP4 ) type call, coupled with a error_reporting() flag that could be used to flag obsoleted things in order to make it easy to bring
Re:Experiences (Score:2, Informative)
Re:Experiences (Score:3, Informative)
YES!!!! Not just names, but parameter order as well. Most the functions work one way, but there are just enough that reverse target parameters that you can never be quite sure you got it right.
PHP: Over a billion functions served... and counting.
Re:Experiences (Score:4, Insightful)
And why we have a lot of high traffic sites that have no issue with it...
Threading != Scalability. Threading is only needed if you do certain types of tasks that need it.
In programming, there is no silver bullet, there are lots of tools suited for different jobs, PHP fits in a lot of those places, Java in others, other languages elsewhere. Threading isn't a "Oh, I'll multithread it, that'll make it faster" type of magic button.
Parent
Re:Experiences (Score:3, Insightful)
Turing-completeness also states that, technically, there is nothing Python can do that Whitespace can't. That doesn't mean you have to use Whitespace..
OOP (Score:5, Insightful)
Re:OOP (Score:2)
Re:OOP (Score:2)
As a long-time OOP skeptic and criticit, I have not seen very convincing examples of of these (except maybe for systems software). I don't want to start an OOP war, but am just suggesting that people not use objects just because somebody says to (unless they are your boss and order you).
"Organization of code" tends to be very subjective. What makes one brain ha
Re:OOP (Score:5, Insightful)
I am with you on this one, although, unlike you, I used to be swept up at one time in all the early OO hype to a degree (back in the Smalltalk days - which by the way is probably the only coherent OO environment), only to realise, by experience, that it was for the most part just that: unsubstantiated hype. Object Orientation has applications, notably in situations close to its original aims of simulation of physical universe (as in the Simula language which started it all), which in modern software is found in things like PC games. But this paradigm has been overused, abused and stretched beyond its breaking point to try to cover all possible cases, no matter how ill fitting. And in the process it has consistently failed to deliver on most of its promises (other then to pad pockets of various charlatans and OO "framework, IDE, grill and taco stand" makers). My experience has thought me that contrary to what OOP priests wish us to believe, "complexity hiding" (usually by masking it by more OO-gunk complexity) is not the answer to reusability, cooperative maintenance and so on. The answer is: simplicity. That is the most maintainable code is the one which can be fully understood, with ease, by the programmer. OOP does not do that. In fact it introduces a whole new gamut of problems dealing with the hidden workings of pyramidal heaps of classes found in any OOP "framework", each with its own weird quirks and inconsistencies, from which you are supposed to "derrive" your own, as long as you adhere to a million of unwritten and poorly documented rules of use of these, supposedly, "reusable" and "extensible" components. Not to mention that it actively encourages creation of massive, incomprehensible class jungles as one can easily see in places like the JDK.
Speaking of PHP, its success can be attributed to its simplicity, ease of use and short learning curve. If they keep continuing to "innovate" new piles of ever more trendy crap into the language, it will soon (already is?) lose this advantage. It won't be long before someone comes up with another simple server-side language to replace the morass and the enthusiatic crowds will move onto this new "lighning fast, low footprint" language and begin to "improve it". Rinse, repeat.
Parent
Re:OOP (Score:3, Insightful)
Consider the Unix read() function, which can read from any file descriptor: regular file, block or character special, socket, and so on. If you were to write such a function in C, you'd write some code to determine the underlying type of descriptor. Then, based on that type, you'd call a helper function - read_file(), read_special(), read_socket() - to perform the actual read.
Guess what? That's OOP. The f
Re:OOP (Score:5, Insightful)
If you're a programmer, I guarantee that you're using SEP (Spiritual Extrusion Programming) even if you don't use a SEP language.
Consider the Unix read() function, which can read from any file descriptor: regular file, block or character special, socket, and so on. If you were to write such a function in C, you'd write some code to determine the underlying type of descriptor. Then, based on that type, you'd call a helper function - read_file(), read_special(), read_socket() - to perform the actual read. Guess what? That's SEP. The file descriptor is the Spititual Manifestation of a Concept. The code at the top of read() is determining the object type (or Spiritual Element). And the helper functions are Spiritual Invocations. If this is a big project, odds are you'll put all the helper functions for sockets in socket.c, for files in file.c, and so on. And there we have Spiritual Encapsulation (of the namespace variety) too.
As noted many times, you can write an SEP in any language. It's just easier to do it in a language that's designed for it.
And so on, etc.
Newsflash: all of the concepts you describe are 1) long in existence before your favourite paradigm arrived on the scene so that you can try to contort them into it, and 2) can be interpreted ad infinitum with any of the millions of "paradigms" one can concoct on the spot. That is because your paradigm is merely a perspective and not an universal (and only) truth. The whole point of abstract formulations, such as computer software, is that they can conform to nearly infinite number of perspectives and can be projected onto the real, physical universe in an equally large number of ways, which is what makes this whole Information Technology thing so powerful.
But I fear that long after OOP has been relegated to the dusty bin of history, some ctr2sprt of the future will still argue about how you are really always writing "Quantum Parallax" code, even if you are you are not ...
Parent
Re:OOP (Score:3, Interesting)
Sadly, the main use for PHP is to jam out a script to get a job done. Much as I love objects. I can't help but notice that my primary use of PHP is to grab a string of data from MySQL, pack some HTML around it and present the string to a web server. Writing
Re:OOP (Score:2)
And I'm not even sure I'd go that far. Consider, for example, OCaml's module and functor system which allows for a very high degree of code reuse, and a type of encapsulation. It certainly allows for information hiding and a tight type-based relationship between data and functionality.
Hosting services stuck on PHP4 (Score:4, Informative)
FYI.... PHP developer articles updated daily:
http://www.devpointer.net/browse.php?l=p&t1=1 [devpointer.net]
RSS:
http://www.devpointer.net/browse.php?l=p&t1=1&fmt
Not The Best Choice For Maintainable Code (Score:4, Insightful)
This is what I was thinking the entire time I was reading the article. I mean, it's one thing to have to whip up some small project for yourself, it's another to build a project that is maintainable by a group of people.
I'd bet that Brian W. Kernighan and Rob Pike (The Practice of Programming [bell-labs.com]) would probably recommend against using it. It doesn't provide for clarity, nor does it simplify, it just makes things "easier" for the guy that writes the original code.
Re:Not The Best Choice For Maintainable Code (Score:2)
What? I'd argue that:
$customer=new Customer();
$customer->name="Bob";
$customer->phone="555-1234";
$customer->insert();
is much more clear than
$conn=mysql_connect("localhost","user","password")
mysql_select_db("customers",$conn);
mysql_query("insert into customers (name,phone) values ('Bob','555-1234')",$conn);
mysql_close($conn);
It's cleaner and easier to read.
Kinda Like Ruby (Score:3, Insightful)
Ruby? (Score:3, Insightful)
I would like to be the first to say... (Score:4, Funny)
http://en.wikipedia.org/wiki/Simula [wikipedia.org]
Y
Crap... (Score:5, Funny)
"Slashdot | Going Dynamic with PHP"
Interesting, but ... (Score:3, Interesting)
Perl is another alternative, and admittedly a pretty popular installation (I imagine anywhere that offers PHP hosting also offers Perl) -- but for someone like me who wants to do the occasional scripting the language is not exactly ideal -- nor is it especially easy to read someone else's code. I think Perl developers are incidentally the most "guilty" party of poorly commented code in FOSS projects, which doesn't help matters.
As a designer and occasional scripter I was interested in learning more PHP at one time, but now I feel as though it's a bit of a dead end, especially for "bigger" projects. Learning Python seems to be time better spent at this point; I can run a native interpreter as well as Java and .net based interpreters to handle more "enterprise-sized" projects; Python has a stronger OO foundation than PHP in existing versions, is designed to easily integrate with C modules, and reads easily. It's also shown itself to be equal to a broad spectrum of applications from commercial tax forms software (QuickTax) to web application frameworks (Zope) to HTPC frontends (Freevo) to P2P software (BitTorrent).
As for PHP, roll me over when version 5 is standard across the board and I'll consider taking another look at it.
DB_DataObject (Score:2, Informative)
http://pear.php.net/manual/en/package.database.db
Awful use of regex (Score:3, Interesting)
Let's see how it can be done better:
Re:PHP 4 V. 5 (Score:3, Informative)
Re:PHP 4 V. 5 (Score:5, Informative)
There's a good summary on Zend: http://www.zend.com/php5/andi-book-excerpt.php [zend.com]
Basically, PHP 5 adds proper object support (think Java-style) including iterators for objects, and new extensions add good XML support, SOAP, SQLite, better MySQL support (prepared statements, OO interface, etc.)
I'd recommend reading Adam Trachtenberg's book Upgrading to PHP 5 [oreilly.com] if you're familiar with PHP 4.
Parent
Re:PHP 4 V. 5 (Score:3, Insightful)
Re:PHP 4 V. 5 (Score:5, Insightful)
Not enforcing Object Oriented programming is actually a very good thing, one of the few good things in PHP5.
Giving the option to use OOP (with a good object system, which PHP doesn't have) is good, forcing it on the poor user and preventing him to write as much as a line of code outside of a damn class is stupid, and is a god damn failure of both Java and C#.
While OOP is a good idea for some problem, others are better solved using more imperative or functional styles. That's why I much prefer Ruby or Python to Java: while they have great object models, they don't try to beat you with an ugly stick if you don't wrap every damn thing in a useless class that is only here because the language absolutely forbids you from doing otherwise.
Parent
Re:PHP 4 V. 5 (Score:5, Informative)
Also, some deprecated functionallity has finally been dropped. All in all, I've been using PHP5 for awhile now and everything works alot faster as a whole (as I use it with Apache 2 as well).
One note that might concern you, PHP5 does not come with MySQL built in anymore. You either have to download the update or compile it yourself. It's nice for those who want to use something aside from MySQL and don't want to have to keep it the module loaded constantly but it's also a pain for the beginner hobbyist who has never had to deal with installing the MySQL module for PHP.
Parent
Re:PHP 4 V. 5 (Score:2, Informative)
Re:PHP 4 V. 5 (Score:3, Interesting)
Then there are PHP Data Objects [php.net] for a unified database interface (although it is a bit primitive when compared to PEAR DB [php.net] and other DBIs).
Re:A bit off topic... (Score:2)
Infighting between PHP and Perl? (Score:2)
Once you get to know a couple of other programming languages, PHP and Perl look quite similar indeed. (Kind of like VBS and ASP, Java and C#, C and C++, etc. are similar.)
Re:Infighting between PHP and Perl? (Score:2)
Re:Infighting between PHP and Perl? (Score:3, Funny)
Re:PHP (Score:5, Funny)
Oh, but everyone (and everything) can code perl - the trick is to hit the keys in a sufficiently random manner.There. That's either a full-featured web-browser, or a worm which will destroy the entire internet. I don't really dare to run it...
Parent
Re:PHP (Score:5, Funny)
Parent
Re:PHP (Score:4, Funny)
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($
($p{$_})&6];$p{$
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
Parent
Any fool can code Perl... (Score:5, Insightful)
Anyone can write code, but very few can write really great code, that reduces the problem to the essential elements and uses the simplest approach to the problem, with the tool (i.e. language) in hand.
You can write shit code in ANY language. You can also write good code in ANY language (within the limitations of the language).
What you're saying is like "Spanish for People who can't speak in German".
It's nonsense and insulting at the same time.
You need to express yourself or solve the problem within the framework of the language you have.
You might choose a different language for a particular task, but if the language is a given, a good poet (or programmer) will make the best of it.
A better language doesn't make one a better programmer (or poet).
Parent
Re:Any fool can code Perl... (Score:3, Insightful)
I agree with this point for good programmers, but for inexperienced programmers a better language can certainly make one a better programmer. The common example is VB, which allows people with basically no programming experience to develop simple applications. But even Java's success in enterprise software is due to the proliferation of design patterns such as EJBs and MVC -- which have basically been ingrained into the language itself. These patterns
Re:PHP (Score:4, Funny)
And, for some reason, I'm always left with this mental image of a tall, pasty elder geek sitting in that proverbial Mom's Basement, pulling on his long pointy beard whilst his Gentoo box spends it's 28th hour compiling a boot-loader or something, smirking as he sees his, ahem, 'Perl of Wisdom' slide down the Slashdot page like a turd in summer.
I just fucking hate you, why bother posting at all?
Perl: The Language for People Who Can't Be Arsed to Investigate the Right Language For The Task At Hand.
Perl: 'Cos You Never Really Moved On.
Perl: Why Use the Standalone Screwdriver When There Is A More Fiddly One Attached To This 52-Way Swiss Army Knife?
* Retrieves dummy and calms down *
Parent
Re:PHP (Score:3, Interesting)
They are always upset when anyone chooses any other language for any purpose, because, in any touted feature of any language, you can do exactly the same thing almost exactly the same way in Perl, but better. That is not sarcasm, I am not being ironic, it is flatly true. Often you can literally cut-and-paste t
Re:PHP (Score:2)
They are doomed to reinvent a bastard mishmash of TATMFWTODI (There Are Too Many F*ing Ways to Do It).
Perl was a very bad reinvention and a cludge of almost every C-style shell script language with several old kitchen sinks thrown in.
Ah! Such elegance! I can see Perl is the only way forward! [sigh]