Ask HN: How do I go about PHP?
I've a background in C#, Java and JavaScript but don't know a thing about PHP. Couple of questions
a) How do you recommend I should go about learning PHP? b) Any recommended Editors (I've to use Windows)? c) I spent sometime looking for frameworks and CodeIgniter seems promising. Your thoughts?
Any other tips, books, libraries, frameworks and goodies you would recommend? Any help is highly appreciated.
[+] [-] nuclear_eclipse|17 years ago|reply
- Recommend Editor: "Eclipse PDT" [1] probably has the best tools relating to PHP development, although I just use Vim for all of my PHP work.
- Bookmark the PHP online manual [2], and add their search plugin to Firefox, so you can look up standard library functions just by typing it into the search bar.
- The Zend Framework [3], more of a great library than a traditional framework, is probably the best resource for any projects your may be starting from scratch, although CodeIgniter is definitely a top contender.
Probably the best way to learn PHP itself is to read the (rather well-done) PHP manual, which includes everything from an introduction to the language, it's parsing and syntax trees, all the way up to how its object model works, and complete references for the entire function library, and all standard modules.
Read some source code from the wild. I suggest Mediawiki and Drupal.
Key points to make sure you understand:
- Arrays are the archetypal datatype in PHP, and can be used as lists, dictionaries, or a mix of the two.
- You can do just about anything just by using the standard function library. Frameworks are not necessary, contrary to popular belief.
- Objects are a mishmash of arrays, structures, and standard C++/Java objects. You can add class variables, functions, and such at runtime.
- You can do a lot of "fancy" meta-programming in PHP; you just have to know how to accomplish what you want. The PHP library helps out a lot with this.
- Everything is a template. It may be a bit more verbose than compiled templating dialects, but PHP itself is a really handy templating system in it's own right, just using <?php and ?> tags.
[1] http://www.eclipse.org/pdt/
[2] http://www.php.net/manual/en/
[3] http://framework.zend.com/
[+] [-] senthil_rajasek|17 years ago|reply
Up vote for that bullet, specifically for PHP.
[+] [-] nuclear_eclipse|17 years ago|reply
- Convert numbers to strings and vice-versa - Compare strings to numbers - Typeless versus typed comparisons (== and ===) - Array keys using '10' (a string) versus 10 (a number)
Once you understand the type inference and type coercion concepts, it should be simple to pick up how it affects your PHP code.
Most importantly, PHP will generally do what's most logical/useful/expected when it comes to these topics, so you generally don't need to think about it, but you should be aware of it in any case.
A good reference can be found in the PHP manual, which gives you tables of comparisons between different data types in different situations: http://www.php.net/manual/en/types.comparisons.php
[+] [-] andr|17 years ago|reply
[+] [-] breck|17 years ago|reply
For an IDE my favorite is PHPDesigner by MPSoftware. Eclipse is pretty good too, just a bit bloated if you like something leaner.
[+] [-] KevBurnsJr|17 years ago|reply
[+] [-] oltmans|17 years ago|reply
[+] [-] kungfooey|17 years ago|reply
As with any programming language, the best way to get started (in my opinion) is just to build something. A blog, a guestbook: something functional and useful. In the process you'll become familiar with the language fundamentals. I recommend that you at first build something using no framework (to get an idea of what sort of security measures you need to take, handling DB transactions, etc) and then followup with the framework of your choice.
I used vim/Eclipse for Java, and still use the same for PHP. There is an Eclipse build specifically for PHP, called "Eclipse PDT." There are several others out there (Komodo, Zend Studio) but PDT is free and therefore easier to try out.
I use CakePHP as a framework and find it to meet most of my needs. I have also tried symphony and the Zend framework, but neither of them were flexible enough for me. I have not tried CodeIgniter, but I have heard good things about it. There are some articles on IBM DeveloperWorks that are a good introduction to CakePHP.
[+] [-] mlLK|17 years ago|reply
[+] [-] oltmans|17 years ago|reply
[+] [-] ErrantX|17 years ago|reply
Worth a look.
I always recommend Notepad++ plus a XAMPP installation over any form of IDE. It's simpler in the long run.
As to learning: that is a hugely personal thing. I picked it up over 4 or 5 years (still learning even now though!). If you already have a good grouding in general programming you wont have a problem :)
But with PHP learnign by doing is a good approach :) there are lots of snippet sites out there as well for you to peek through for ideas :D
[+] [-] oakmac|17 years ago|reply
[+] [-] KevBurnsJr|17 years ago|reply
[+] [-] dezwald|17 years ago|reply
CodeIgniter is very flexible and not as strict when it comes to implementing your own code and (libraries/classes/plugins). It's very simple, implements great separation (in regard of its MVC archt.) which makes it easy to understand and use. The framework has great, easy to follow documentation with great forum support and a growing community.
i say just watch one of their video tutorials of their website and you'll see how easy it is to get started on a project.
As for an IDE editor:
if you're using windows....i HIGHLY RECOMMEND PhpED (by nusphere)
I have tested every possible editor out there and this one by far is the BEST. It's fully featured in every aspect, easily customized and runs fast!.
they have definitely taken programmers needs and dumped it into this application.
it's definitely worth a try at least.
just checkout the features here.
http://www.nusphere.com/products/phped.htm
[+] [-] bprater|17 years ago|reply
You aren't constrained by the framework. If you want to do queries in the controller, go for it.
[+] [-] thorax|17 years ago|reply
[+] [-] henryw|17 years ago|reply
[+] [-] oltmans|17 years ago|reply
[+] [-] mechanical_fish|17 years ago|reply
I think that's a pretty good way to go, actually. You want to learn PHP by tinkering with a bunch of (a) working code that (b) has been reviewed by a community of people, at least some of whom are (c) trying to exhibit some taste. The problem with the language is that various sectors of it are poorly thought out, or have been implemented several times, and the best way to avoid stumbling over them is to follow in the footsteps of some expert guides.
Joining the userbase of one or another framework will probably give you much of the same effect.
The language itself is not hard to learn at all, except for the bits that are maddeningly silly. Watch out for the array() and the way it handles keys. Find the handy online table that compares empty() and isset() and is_null() and helps you to figure out that, in many cases, none of them is the thing you really want. ;) Watch out for accidental typecasts and their effect on your logic.
[+] [-] sammcd|17 years ago|reply
[+] [-] cbetta|17 years ago|reply
[+] [-] KevBurnsJr|17 years ago|reply
[+] [-] trevelyan|17 years ago|reply
[+] [-] noodle|17 years ago|reply
b) a quality text editor will work just fine. when doing php stuffs, i use jedit, and have used eclipse and netbeans in the past.
c) see a
[+] [-] paulsweatte|17 years ago|reply
Then take a crash course: http://cs.metrostate.edu/~fitzgesu/courses/ics325/summer04/C...
Then learn about database interfaces: http://www.kitebird.com/articles/php-pdo.html
Then learn about programming patterns: http://www.rosettacode.org/wiki/Category:Solutions_by_Progra...
Then learn about security: http://www.owasp.org/index.php/PHP_Top_5
Then learn about error handling: http://www.w3schools.com/php/php_error.asp
Then learn about debugging: http://www.onlamp.com/pub/a/php/2004/08/12/DebuggingPHP.html
Then learn about idioms: http://www.cybersprocket.com/wiki/index.php/Eric's_PHP_Guide
Then read a comprehensive book: http://www.ubookcase.com/book/Sams/PHP%205%20Unleashed/
Then learn about optimization: http://progtuts.info/55/php-optimization-tips/
I've used PSPad, Komodo Edit, and Aptana Studio Community Edition for PHP editing, and recommend them all.
I've tried CakePHP and Drupal, but had trouble with the documentation and syntax of both compared to pure PHP. Wordpress has great documentation, community support, and readable sourcecode.
[+] [-] texec|17 years ago|reply
b) If have experiences with Java, try one of the PHP Plugins for Eclipse.
c) CodeIgniter is mostly based on PHP 4. This results in same outdated patterns, especially regarding PHP 5.3. If you want real extensibility (and highly object orientated code) try the Zend Framework. If this is a bit too much, i recommend the Yii Framework, it's lightweight and brings lots of ideas from rails to PHP without copying the rails specific approach.
[+] [-] mlLK|17 years ago|reply
[+] [-] unknown|17 years ago|reply
[deleted]
[+] [-] ryanwaggoner|17 years ago|reply
In your case, though, you sound like an experienced programmer in other languages, so you should be fine starting with a simple CRUD app and then progressing to frameworks; any of the popular ones will do fine.
[+] [-] KrisJordan|17 years ago|reply
For editors I highly recommend Eclipse DPT: http://www.eclipse.org/pdt/
With a Java background I would think you'll feel right at home there.
Framework wise stay tuned to (shameless plug) http://www.recessframework.org - it's a framework I've been working on that makes greater use of the OO facilities in PHP5, is RESTful, and has a straightforward ORM. Public preview release soon.
CodeIgniter is written to run in either PHP4 or 5 which means it makes less interesting use of the PHP5 object model. If you're an OO nut I suggest staying in 5 and perhaps looking at Kohana.
[+] [-] drathbun|17 years ago|reply
A good intro to the basics, which will allow you to make use of the online docs, which is the best documentation of a programming language I've ever seen.
After that, the other resources come in to play. For an editor, I use notepad++ on the pc and textwrangler on the mac. With apache, mysql, and php running locally, your development platform is free.
[+] [-] tdonia|17 years ago|reply
http://www.php.net/docs.php
i would suggest downloading a version of it for quick reference. it's worth learning the commonly used functions, but a big chunk of php's value (and the main criticism against it) is a namespace filled with goodies (with varying degrees of good). This means there is probably a lot of useful functionality that's used sporadically enough that it's not worth committing permanent headspace to. Rather, learn to be quick about finding the right function to use. It's usually worth checking to see if there's some strange function/module that does exactly what you're trying to do. and if there's not, you can usually find example code in the comments - though i wouldn't recommend copying that code into production. rather, use it as a starting point for exploring the problem at hand.
i'd suggest learning php by giving yourself a well defined, if simple, project to start with and attacking it the same way you've learned languages in the past. probably with some reading, a lot of doing, occasional breaking, then more reading.
b) notepad++ or homesite are my preferred IDE's
c) codeigniter, cakephp ( http://cakephp.org/ ) and the zend framework ( http://framework.zend.com/ ) are the big frameworks i'm aware of, but i'm sure there are more out there.
enjoy!
[+] [-] oltmans|17 years ago|reply
[+] [-] KevBurnsJr|17 years ago|reply
[+] [-] floodfx|17 years ago|reply
[+] [-] mseebach|17 years ago|reply
Install Doctrine (ORM) and Smarty (Templating engine) or friends and use it religiously. If you do, you can use PHP for what it's best at: Cranking out business logic at high speed.
http://www.doctrine-project.org/
http://www.smarty.net/
[+] [-] rsayers|17 years ago|reply
As far as editors go, I use emacs, but for about 5 years I used UltraEdit and was very pleased with it.
I personally use a framework i wrote a while back, but if I were starting over I think codeignitor would be my pick
[+] [-] showerst|17 years ago|reply
It's much lighter than eclipse, but still has tons of features (regular expression search & replace is a favorite).
Small download, so it's at least worth checking out.