08:21 pm, 1 Dec 04
please explain php to me
I can't comprehend why people use PHP for anything. From all of my (small) exposures to the language I conclude it rates pretty near "horrible". I'd love to hear any explanations. (In particular: how is it preferable to any other language once you have the <? embedding syntax? See, for example, Apache::ePerl.)
I also can't comprehend how this bug can even work. It makes so little sense, it takes me a while to understand what is even going on.
I also can't comprehend how this bug can even work. It makes so little sense, it takes me a while to understand what is even going on.
It's also (in my experience) a lot easier to get running under apache. Just drop in mod_php and go to town, any file that ends in .php is interpreted (if you just use the defaults). Is there any way to embed perl that easily?
...*looks* Oh, eperl is that easy. Well... uhh... still. I'm just explaining my experience ;)
There's also big heaping piles of web software written in PHP... more than Perl, it certainly seems. So when I was starting out, it was much easier to find examples of what I was trying to do in PHP than it was in Perl... though again, I've since learned better.
I dropped it like radioactive waste after watching class constants change value sometimes. Ruby still makes me smile.
I can deploy a new PHP web site as quickly as 1 minute at this point.
When you get clients who want to pay you $1000 for a web site designed and developed from bottom to top with minimum functionality beyond being able to display their art, and want it done in a month, you use PHP. When your clients are paying in the area of hundreds of thousands for their site and want it to run the world, you use things like Java struts, xsp/mod_mono, and at a lesser rate, mod_perl.
There's a lot of design that needs to go into developing sites using the latter. There's not much need for the former, and truth be told, it only slows the process down. PHP doesn't provide a means to do anything but the most simplistic things. But it does them all quite quickly.
I hope this helps.
That is exactly it. Also, that's every client I've ever had :P
I do agree that it's an utterly horrendous language. Every time I look at it, a little voice in my head goes "HACK HACK HACK HACK".
Why do you say it's a hack?
I'm curious why you say it's a hack? It's obviously based on the C language, with lots of the difficult parts taken out and some intersting OO parts put in.What seems particularly "hackish" to you?
Ah, you've hit my personal soapbox!!
There were two reasons to use PHP back in the day:- Auto-importing of variables: Any variables in the POST or GET request would just be set in the outermost scope of your page. Very handy, but very insecure. Therefore, it's been turned off by default since PHP 4, and most people are leaving it off. You have to manually import them all, which is just as ugly as the Perl equivalent for the job.
- Intermixing code and layout: You could just write the PHP amongst your HTML and get things done quickly. This sort of thing has been abandoned by larger/more professional sites in favor of Smarty templates, to allow for things like internationalization and user customization. People use Smarty because it's a compiled templating engine, so it's decently fast; doing it otherwise is slow. Of course, you could just use a perl templating engine in much the same way.
Nowadays, you should just bite the bullet and learn how to be a decent perl programmer. If you want to do a large-scale site, you're going to need something like mod_perl. There exists something similiar for PHP, but it has some serious implications for rollout (i.e.apachectl gracefuldoesn't work anymore). So, yeah, basically, i don't fucking get it either. PHP just has a low barrier to entry and serious momentum behind it, i suppose.Who will write mod_intercal?
Who will be our champion?!Huh, seems like someone's written mod_bf...
But yeah, as a language php doesn't seem very special.
I'll stop there, my next rant on PHP will be in my own journal :|
This can't be right. All the web servers at my work site (which, unfortunately, is built in PHP) have several (hundred) db connections open to different database servers, since we do user clustering for certain operations.
Most of the programmers here don't know perl, so their scripts that run from cron are written in PHP. Since all their code is geared towards being run from the web, I end up having to write shell script wrappers that chdir to the right directories, set up a few env vars, and then exec their scripts. Also, even though I'm just the sysadmin, I end up writing a few scripts here and there, mostly cron jobs to frob the databases. I write my scripts in perl, which makes them my responsibility (they can't or won't modify them if I'm not around).
So I've written my thoughts here: http://revjim.net/item/10195/
I tend to be a bit long-winded, and I'm sorry for that, but I'd really appreciate any insight you can offer.
In regard to that bug... yeah... I don't see how it can work either. I can say, however, that in the many years that I've been programming in PHP, I've never run into this bug. Based on the examples being presented (and some knowledge of PHP reference passing is needed to clearly understand the last example) it seems as though it mostly likely has to do with the reference stack. PHP has always been a bit odd in regard to references and I've found non-intuitive behavior in regard to references in a few cases. While I agree that this problem seems quite absurd and makes you wonder what ELSE might be going on behind the scenes, I have never run into anything (despite my down right abuse, at times, of the language, just for fun) that was truly affected by this bug, or a bug like this.
But also note all of the reasons given above why people use it: it's commonly available, it often comes with some software preinstalled, it's easy to learn. Coming from my background (looking at complicated languages that aren't necessarily practical), those aren't the sorts of things I find useful when evaluating a language.
Regarding your post, see the section "The Blub Paradox" in Paul Graham's Essay. And my "horrible" evaluation is just the general hackiness/quirkiness I've encountered; it's very possible that if I were more familiar with the language it's make more sense to me. You definitely always ought to choose the language you think would do the job best for any job you're doing, so you're right to choose PHP for whatever you do. Generally what has motivated me to switch languages in the past is a general feeling of "enough! problem [x] is just too much to bear!" But I also dig learning about these things.
I can't really comment on it's merits over/under perl. I can say that I use it every day for not-so-simple forms and libraries and it works fine for me. The syntax is similar enough to Java or C that porting existing code is trivial. For instance we rewrote some of this stuff in PHP 5 and it went quickly. PHP 5 is not the sea-change most people expected, but it has quite a few niceties gleaned from the Java world. There is a growing contingent of PHP developers interested in programming patterns, test driven development, agile programming, etc, etc. thanks to some of these changes in PHP 5.
In the beginning, I used PHP to get simple things done, and it worked well. As I've become a more learned developer I can still get things done in PHP. I've never encountered an issue with that bug. It's a stupid bug for sure and the example case could have been written more clearly. It's indicative of the copy/reference inconsistencies that have plagued the language up to today, but you learn to deal with those pretty easily. There are more serious issues worthy of exemplification, such as PHP 5 memory leaks that make writing daemons a PITA. Most of these aren't show stoppers for people who want to get things done, though. If it's an extra line of code, it's an extra line of code. It's just important to know the limits of your tools and to work toward using them well in your craft. There are plenty of php programmers that do. Just as there are many Perl programmers that do, too. I don't have to tell you this, though.
If I don't provide a very compelling argument, that's because there probably isn't any argument to be had. It's a trench language, definitely not for the pure computer scientist and/or perfectionists in the world, and that's ok. While I disagree with your assertion that it's "horrible", I know it's simplistic and often inelegant.
OK, maybe I will rant a bit - moreso about the social aspect of php.
Maybe for me it also has something to do with snootiness? The reasons that other people always give me as "why they love php" (lack of proper scoping, easy inlining, loose syntax checking, etc) are the same reasons that I dislike it, and maybe I want to searate, my "programmer values" from theirs.
Also, it confuses me that so many people "know" php. Or care enough to go around telling everyone the "know" it. I don't understand how someone can selectively "know" a programming language, but have no interest in "knowing" others. Once you reach a certain point, it becomes obvious that most all programming languages are similar, exist (for the most part) to solve similar problems, and vary only on how thier set of tools is implemented.
Is it not the goal of every programmer to learn as many languages so they have as many tools available to work with as possible? Why is it that everyone I know who totally loves php desires to use it in every situation, even if it obviously does not fit?
A few months ago someone even gave me a php script. That blew my mind.
Let me explain my dislike for php developers in this hypothetical situation:
ME: "Hey team, I need to write a [perl/java/c/python/whatever] app. Who would like to help me?"
TEAM: "We don't know [language]!"
ME: Well, you could brush up on it. You are all developers (according to your resumes), and it shouldn't be a mind blowing concept for you to explore another language.
TEAM: Sorry, no can do.
- vs -
ME: "Ugh, I need to make some bug fixes to an app. Who would like to help me?"
TEAM: "What is it written in?"
ME: "...php"
TEAM: "AWESOME AWESOME AWESOME. *I* TOTALLY *KNOW* PHP!"
This is the point where everyone gets excited and starts telling me how they wrote a shopping cart app for their grandma in php, and how it doesn't work quite right and how people keep breaking in to it, but they would totally love to help me on a php project!
Why does that happen? I actually have people come up to me at work and say things like "So...I hear you are working on a project...using php. That is so cool, I love php". I don't know why this happens. Do people feel a special attachment to php that I don't understand? Isn't it just a tool (although a funny shaped one)?
I do prefer Ruby as a language, but whenever I try to use Ruby I find that its syntax is so different from what I spend all of my workdays on that it takes quite some time to get used to it. Since I do my personal hacking in one- or two-hour bursts in the evenings, I don't have time for that much page-swapping. And my web host doesn't support Ruby, and from what I hear, Ruby is just too slow to use for big applications (whereas I keep hearing about sites like Friendster that switch from Java to PHP and get faster.)
I probably would use Perl instead of PHP if I didn't think that Perl was the goddamn most fucking wretched language EVAR. Its syntax is a clumsy agglutination of sh, sed, awk, C and they probably threw some OS\360 JCL into it too. And it's full of "clever" special case shortcuts that let you write some typical filter script in four lines of gibberish, but will stab you in the back by doing something completely unintuitive in other contexts. And the whole bizarre $/#/whatever prefixes for variables being used as scalars vs. arrays never makes any sense at all to me no matter how many times I've read about it.
So PHP seems like a decent tool to use. I completely agree that as a language, it's amateurish (though less so than Perl IMHO). But I try to overlook its flaws (which are nontrivial, especially its totally screwy arrays) and use it as a means to an end. I've been extremely happy with how fast I've been able to a web app together with it.
Basecamp
43 Things
And an entire web-based order processing system for some educational competion site whose name escapes me.
No, Ruby is not 'too slow' for anything.
(All of theoretical interest since my web host doesn't even seem to have Ruby installed on their servers.)
Rails provides an MVC-like framework that uses erb templates. With Rails you can have a working mockup of an application with a few hours work (if you've never used Rails before). Faster otherwise, Rails is built to do lots of heavy lifting.
"The IMAP extension cannot be used in conjuction with the recode, YAZ or Cyrus extensions. This is due to the fact that they both share the same internal symbol." -- http://www.php.net/imap
'sokay
PHP sucks as a programming language as much as HTML sucks as a display description language. Somehow, they are both absolutely suited for the task at hand. Surely the generosity of these languages allow people to commit severe abuses (both purist and practical). On the other hand, those of use coming from more disciplined backgrounds are able to use these tools in a manageable and I dare say professional way. One important point, though, is that a LOT of PHP code, like HTML code, is throwaway.There is almost nothing to PHP as a language -- it is run in a scripting engine, it has a fairly rudimentary and c-like syntax, it has a default configuration which fairly much allows anyone with half a clue to use it (which can be dangerous, of course). The real feature which is exciting is that it has thousands of built-in (natively compiled and well-tested) functions and many of them are targetted at web-delivery problems. This is a boon to anyone who simply wants to get something done without first having to write a lot of library code.
One often stated goal of PHP is not to have too-much magic--almost everything is done via function calls. If there is a function you don't recognize, you simply plug it into the online manual and you know what you are dealing with.
In addition to the builtin functions you have the ability to load/define any number of additional custom functions through binary modules -- and there are already plenty available. This makes it relatively easy to allow your custom libraries to be scriptable making for quite an extensible language. Another nice thing (for some of us) is that it doesn't (or hasn't) tie you into some grand programming paradigm (say, I dunno, OOP).
So I'd say it is the fact that it has a liberal license, is actively developed and maintained, is relatively fast, easy to install/maintain, simple to code against, maintains a familiar syntax, allows participation by many skill levels and permits the creation of structured code by those with adequate skills. The fact that it can be abused and used to create decidedly unstructured solutions isn't so much of a problem as it may sound; poor solutions are rarely adopted by more experienced coders and solid solutions are often packaged as libraries which tends to hide complexity from newbs. Oh, did I mention it scales exceptionally well? Another nice thing: PHP can be used to do proof-of-concepts that actually WORK. High-performance can be stubbed-in as time, budgets and needs permit.
Anyways, Evan, I wonder what in particular you find so distasteful? Here's what I find distasteful: a colleague of mine (who is an excellent low-level, high-performance library kind of guy) struggles trying to web-enable his apps using c/c++ and often ends up having HTML embedded in strange ways into his applications. If he would listen to me and stick to the library portions of the code then the rule-modeling could be done in PHP and/or Java and the display could be done with PHP templates. This would not only lead to more manageable code and a better overall work-flow, but it would mean that simple things could be changed readily using lower-powered resources (ie. less trained/costly staff). My projects have gone exactly that route and because I am using an excellent PHP template engine (Smarty) I can even farm out display tasks to end-users (who are concerned about those things anyways) without worrying about security implications. Turn-around time is stellar.
For the way you work, PHP may have no place in your tool-chain. On the other hand, I believe that anyone who needs to do web-based work (and increasingly other types of applications as well) ought to look more closely and not get bogged down by some of its relatively minor idiosyncracies. By all means, don't try to get a feel for what PHP can do for you and your projects by perusing the PHP bug list!!
xo boots
easy deployment, easy learning curve
PHP works great, easy deployment (even in Windows) and easy learning curve.perl? no thanks.
anyway if you don't like PHP it's not a problem; lots of tools out there anyway. which languages/platforms do you recommend, those that don't strike you as "horrible?"
PHP $Variables
PHP's super string all-in-one lists as both arrays and hashes variable does have a certain simplistic charm to it. When trying to turn developers into Perl programmers they always choke on the $string vs. @array vs. %hash vs. \$reference thing.