Fog Creek Software
Discussion Board




PHP overview

I'm completely familiar with HTML and CSS, and have tinkered in Javascript.

I barely understand the basics of PHP, but it seems like a powerful way to create flexible and future-proof (or future-resistant) websites. 

How do you use it/find it useful?  Am I misguided in my understanding?  I'm considering devoting some time to learning all the ins and outs, and I'd like to know what other think.

EAW
Wednesday, November 12, 2003

I'm just getting into PHP too, and I'd like to add a few specific questions:
1. I know there are debuggers available for PHP, but do you have to have an IDE to debug?
2. For those who do PHP on a regular basis, do you find it easier/faster to use an IDE?
3. If you use an IDE, which one?

HeyCoolAid!
Wednesday, November 12, 2003

I did a small website in PHP, since that's what our web host had installed.

I hated every second of it.

No debugging capability at all. No module system or namespaces, all you had was include. Almost nothing pre-built.

The language is the typical ball of mud you get from something that just gets thrown together without being willing to go back and clean up afterwards.

For an embedded HTML language, there's suprisingly little (i.e. none at all) features available to actually make generating HTML or processing forms easier. I wrote a simple event signup form, and by the time I'd finished writing all the validation logic I had almost 1000 lines of code. This should be built in!

And PHP is incredibly sensitive to how it's configured, and the site administrator can radically change how your site functions by tweaking the initialization file, and you've got no control over it whatsoever.

Chris Tavares
Wednesday, November 12, 2003

A couple of years ago, PHP was pretty great for putting together medium sized web applications.  These days, even if you consider PHP 5.0, it doesn't even begin to hold a candle to what ASP.NET offers.

Unless you're rabidly anti-Microsoft, I suggest you take a look at ASP.NET in addition to PHP.  Even if you are rabidly anti-Microsoft, consider checking out the ASP.NET implementation of the Mono Project (unfinished, but still quite usable).

Mister Fancypants
Wednesday, November 12, 2003

"No debugging capability at all. "

PHP Debuggers:
http://dd.cron.ru/dbg/
http://apd.communityconnect.com/

IDE's:
http://www.phpedit.net/
http://www.nusphere.com/
http://www.zend.com/store/products/zend-studio.php

I use Textpad, so I can't say what's better.

"For an embedded HTML language, there's suprisingly little (i.e. none at all) features available to actually make generating HTML or processing forms easier. I wrote a simple event signup form, and by the time I'd finished writing all the validation logic I had almost 1000 lines of code. This should be built in!"

Try:
http://pear.php.net/packages.php?catpid=10&catname=HTML

1000 lines of code eh?  Simple sign-up form?  Sounds like a problem between the monitor and the chair to me.

Matthew Lee
Wednesday, November 12, 2003

I believe the poster was looking for PHP info, not anti-PHP spew.

I believe Zend has an IDE with a debugger.  I personally have not used it though.  Most of my debugging is accomplished via standard output mechanisms.  I know... archaic, but it suffices for the vast majority of what I do with PHP. 

Some other things to read up on:

Pear (http://pear.php.net): A repository of different modules for PHP.  This includes a database abstraction layer, HTML forms utils, and much much more.

Smarty (http://smarty.php.net): A templating system to separate content from business logic within PHP.

There is a lot to digest in there.  I would recommend just playing with one of them at a time until you get comfortable.

Also, for pear, I highly recommend taking advantage of this handy dandy web-based installer (follow the instructions at this link):  http://go-pear.net/

Master of the Obvious
Wednesday, November 12, 2003

" Sounds like a problem between the monitor and the chair to me."

Classic.

Master of the Obvious
Wednesday, November 12, 2003

One more thing.  This comment by Chris:

"... the site administrator can radically change how your site functions by tweaking the initialization file, and you've got no control over it whatsoever."

is completely wrong.  You can easily override the ini settings to configure them to your liking. 

Master of the Obvious
Wednesday, November 12, 2003

I'll second the Smarty proposal! Execellent piece of software. Nicely written too!

Jilles Oldenbeuving
Wednesday, November 12, 2003

"...is completely wrong.  You can easily override the ini settings to configure them to your liking."

You can? Where was that documented? I could never find it.

I'm just a poor windows schlub dropped onto this PHP web server, running an older version of PHP without ANY of the Pear stuff installed.

As far as my 1000 line script is concerned - yeah, maybe it was me, but I don't think so. I did my best to centralize as much as I could, but all I could think was "if I was using ASP.NET I could do this in zero lines of code."

Chris Tavares
Wednesday, November 12, 2003

"No debugging capability at all. No module system or namespaces, all you had was include. Almost nothing pre-built."

Ironically, I consider this an advantage of PHP.  The base language is extremely low-level but surprisingly powerful.  It's designed (and more so in PHP5) to be extended at a higher level by PHP code itself.

For example, PHP exposes all the low-level interfaces of all the database platforms.  For MySQL it exposes almost 1-to-1 the MySQL C interface.  That's the same for Oracle, Postgres, Interbase, etc.

Now if you want RAW performance, you can go right to that level and tune to a specific database.  But more likely, you want a high-level objected-oriented database layer.  You have several choices.  For example, you can use PEAR-DB which is bundled PHP as part of PEAR framework or use ADODB which is modelled on ADO or roll your own (it's not that hard).

There has been some debate about namespaces; but with PHP scoping rules they don't make nearly as much sense in PHP as in some languages.  In the end, you get the same effect with classes and name prefixing.

There are lots of debugging facilities both from Zend (the company that makes PHP) and free 3rd party tools.  Check out the Zend IDE on their website www.zend.com.  You can step through PHP code, set breakpoints, etc.  I don't, however, use it.  I use the built in error handling facilities and good'ol print statements.  I have all errors (complete with stack trace or DB query) emailed to me whenever they occur on a production installaion.  Very handy for finding problems.

As for "all you have is include" -- that's a raw-level primitive that can be extended as well.  I have a VERY large project without a single include statement.  I created a function called import() which takes a class or module name.  It then goes off and finds the appropriate file and includes it.  In PHP5, import() isn't really needed -- a function will automatically be called whenever you try to instanciate a class isn't currently loaded -- giving you a chance to include the appropriate file.

You mention ASP.NET without talking about the .NET framework.  In PHP, the default framework is PEAR which includes form validation, database abstraction, and pretty much everything else.  Furthermore, It's not the only framework!  There are different frameworks for other purposes (or you can roll your own) and you can mix-and-match.

I'm definitately not saying that PHP is better than ASP.NET -- I don't think it's that simple.  I do think they both have their strengths and weaknesses depending on your environment and the project at hand.  Some projects are just better for each.

I think ultimately the choice of ASP.NET vs. PHP is less about the respective languages and rather the respective platforms.  If you're committed to hosting on Windows then you should go with ASP.NET *period*.  However, I personally I think that Unix/Apache is a more appropriate web hosting platform than Windows/IIS in general.  Which then rules out ASP.NET.  I would not want to go back to hosting on Windows -- that was painful.

Almost Anonymous
Wednesday, November 12, 2003

Chris- I feel your pain.  We've all been thrust into projects where we don't know the language, don't know the toolsets.  That's a challenge regardless of what tech you're talking about.

A Honda mechanic dropped into a BMW shop doesn't say "BMW's are shit" just because he doesn't know where the alternator is.  he gets out the service manual and finds out. 

As for documentation of configuration overrides:
http://www.php.net/manual/en/configuration.changes.php

It's been there for years.

ASP.NET may be easier and better, but this poster didn't ask about ASP.NET.

Matthew Lee
Wednesday, November 12, 2003

"You can? Where was that documented? I could never find it."

Open my handle winhelp searchable documentation for PHP and search for "php ini settings".  Oh, there it is...  function "ini_set".

"I'm just a poor windows schlub dropped onto this PHP web server, running an older version of PHP without ANY of the Pear stuff installed."

You can install PEAR yourself.  It's all just PHP code.

"As far as my 1000 line script is concerned - yeah, maybe it was me, but I don't think so. I did my best to centralize as much as I could, but all I could think was 'if I was using ASP.NET I could do this in zero lines of code.'"

Go here:
http://nyphp.mirrors.phpclasses.org/browse.html/

Pretty much everything you can imagine has already been written for PHP.  Looking for form generation and validation.  I found a highly rated class library in just a few clicks.  In fact, I probably could have googled for it and found one without resorting to going to phpclasses (which is one ugly website).

Almost Anonymous
Wednesday, November 12, 2003

Chris,

I agree with Matthew; I don't want you to think I'm calling you an idiot for not finding all this stuff.  It takes a while to get up to speed on the language AND what's available for the language.  I just want to point out that it is available and ultimately it's not that hard.

Almost Anonymous
Wednesday, November 12, 2003

I had to do PHP stuff the last few days. I downloaded PHPEdit some time and it sucked big time mainly because it crashed a lot and whatever I tried the debugging would not work. Yesterday somebody convinced my to try again, so I went down to:
http://www.phpedit.net/
and got the latest beta version 0.8.0.25.

For freeware it did really impress me. It looks like the Delphi interface (yes those F9, F8, F7 shortcuts do work, just like Alt+1 bookmarks) and debugging was up and running out of the box. There was even a profiler which worked flawlessly.

In a days work I had two crashes and there are ample of small annoyances, but that's already a 1000% improvement over my previous experience. It is heading the right direction.

If you haven't tried phpedit lately try it again.

Jan Derk
Wednesday, November 12, 2003

The Zend Studio product (their IDE) has a pretty nice debugger.  I've not fully explored (who really has?) the .NET C# debugger to know how they compare, but I'd say that with the Zend IDE you can set breakpoints, watches, look at the stack/variables, etc. which is most of what I do with the C# one.

http://www.zend.com/store/products/zend-studio.php

MR
Wednesday, November 12, 2003

If you want a web resource (or just a free one), http://www.php.net has everything you'd want.

If you want an excellent book on PHP development, get "PHP and MySQL Web Development, Second Edition" http://www.amazon.com/exec/obidos/tg/detail/-/067232525X - it's a great book for learning PHP.

RocketJeff
Wednesday, November 12, 2003

I used Perl for many years and then went to mod_perl which is very powerful. For the last year I've been working at a place which uses PHP on the websites (still use Perl for crons and syasdmn type tasks and really a plethora of things).

I doubt a language can do any "future-proofing". For that I would HIGHLY suggest code organization. Modular, OO etc. I dread most PHP code I see as most of it is written in what I call a stream of consciousness style but I've seen that in Perl as well.

If you are going to do PHP, BY ALL MEANS, invest the time you may need to spend to understand PEAR and something like Smarty (I used TT2 in Perl and HT as well).

I don't think the language is so important as the understanding of application architecture. That said, I choose to do all my personal projects in PHP for the ease of deployment. Using CPAN or Pear and TT2 or Smarty takes me about the same amount of time to develop.

Whatever you do, please don't start writing html and php and use globals and rewrite the same code over and over again.

Also, about debugging. I never understood this.  I use Textpad and Emacs and Vim and I just read the code. Perl has the REQUIRED 'use strict, use warnings' which will catch 99% of any problems and PHP has it's error_reporting which can be handy.  I don't use an IDE. The IDE's that I've seen have only scared me. I think knowing the code and typing 70wpm and using Perl to write code, and knowing your text editor and tools like using etags is pretty powerful. I have  a strong aversion to the time wasted moving my hand from keyboard to mouse.

Me
Wednesday, November 12, 2003

"I believe the poster was looking for PHP info, not anti-PHP spew. " - Master of the Obvious

Actually,  i don't mind the spew.  By all means, tell me what's bad about it before i waste time learning something that won't help me.

And feel free to pitch other solutions (eg ASP, etc).  As I mentioned, I'm just grasping how all these interact, and I'm trying to make an educated decision about which one to invest time in learning.

(an aside: I know you can't fully answer my questions without knowing my scenario better.  However, hearing your experience with various languages for various uses helps to inform.)

thanks for the all the feedback already.

EAW
Wednesday, November 12, 2003

If you want to use PHP to manage the contents of a web site, you're better off starting with a CMS (written in PHP, if you prefer) instead of reinventing the wheel.

www.cms-list.org
www.cmswatch.com

Frederic Faure
Wednesday, November 12, 2003

For years I've used HomeSite for my PHP editor.  Over the past month, I've been trying various IDE's so I can get the benefit of debugging and profiling.

Nusphere's phpED is really solid and works great, but for personal use, the $299 price tag is a bit much.

I've tried Zend's IDE, too, and just don't like it.  Particularly the setup for debugging, but I haven't tried the most recent version.

The free PHPEdit is getting very close to phpED in its functionality.  It does still lack some features, but it's still not at a v1.0 release stage yet.  There are a lot of things I like about it though.

I still don't think I've found a really great IDE for PHP though.  Nothing on par with Visual Studio for MS development.

Wade Winningham
Wednesday, November 12, 2003

I really don't know why people doesn't mention Active State's Komodo IDE.

Komodo is simply great IDE whether you want to write code for Perl/PHP.

It has all the features which Zend/Nusphere supports + Visual Studio like feel. Another feature I like is the inbuilt reg ex builder, support for collapsing/expanding code block are very very useful.

JD
http://jdk.phpkid.org

JD
Thursday, November 13, 2003

I have done some PHP and I realy didn't like it. As far as the language is concerned, to me the comment above that reffered to it as a "ball of mud" is going gentle on it. This thing howls " no architect here, just barf up wathever you fancy and it's included".
It is painfull to remember but I have shrouds of nightmares about globally scoped, automatically instantiated, case sensitive variables. In many ways it felt like a Basic from the 80's. Strings weren't even Unicode, which led to internationalization nightmares. XML support was immature to put it mildly, and speed was, what can I say, abysmall. Maybe this was because we were outside of its native environment, Windows, where you were offered the choice between the self proclaimed "unstable" ISAPI release and the "Why are those snails hunking their horns behind us all the time" CGI implementation.
I am sure part of the nightmare was the code I inherited, but the language certainly didn't help.
Now the real kicker for me was the lack of support: breaking changes in every point release, and only the very last release gets the security updates.
If you want to script together a few homepages or a simple personal CMS, go for it, but if you are tinking about doing anything more serious, I would advice against PHP.

Just me (Sir to you)
Thursday, November 13, 2003

EAW, like Frederic and other posters have suggested, most trivial things like forms, validation, etc have been written already. No reason to reinvent the wheel.

Another resource you might want to look at is

http://www.hotscripts.com/PHP/

lots of complete scripts, some tutorials, software etc.

I never start a PHP project without first visiting PEAR (for modules), and Hotscripts (for complete applications).

Tapiwa
Thursday, November 13, 2003

"I really don't know why people doesn't mention Active State's Komodo IDE."

Because it boots about 15 seconds on a fast machine, consumes half your memory, your left hand AND your firstborn, and then is as responsive as if it's struggling to digest all those things?

Proklet
Thursday, November 13, 2003

Proklet,

I agree that start up time is bit too high for Komodo.


But no longer, Komodo is sluggish once it has started! Check version 2.5+!

JD
http://jdk.phpkid.org

JD
Thursday, November 13, 2003

Don't forget http://www.xdebug.org/

Makes variable outputting, stack dumping, etc prettier and easier to read.

It also profiles and has hooks for a debugger, I believe.

cyang
Thursday, November 13, 2003

If you have to work with ASP.Net and Php, you might want to try VS.Php: http://www.jcxsoftware.com/vs.php

K
Thursday, May 27, 2004

*  Recent Topics

*  Fog Creek Home