What are some good resources for learning the fundamentals of the PHP language and an overview of frameworks available? I've been working my entire career in Javascript, C# and, in older days, VBScript.开发者_如何学编程 But now I find myself needing to use PHP for a project due to certain requirements. I don't want to pick PHP For Dummies but I want better information rather than learning as I build for stupid mistakes.
My main points of inquiry are: Zend Framework - Why? Is it akin to JQuery for Javascript just making regular tasks simple? Variable declaration - I've read that PHP is a loose language but what are the pitfalls? How to take advantage of this fact? General good practice structure guidelines. In C# I can create multiple classes and reference those in my Code Behind using statements. Should I apply the same principle to PHP and just include the PHP files on the pages as needed or is there a better method?
I'm looking for answers to my questions but also reliable resources for good, detailed information. I'd rather be able to fish for my dinner if you know what I mean.
The only resource you actually need to consume (and should) is the PHP manual. It's very complete, even though it's low on practical recommendations. And download it!
Here are some book recommendations:
https://stackoverflow.com/questions/90924/what-is-the-best-php-programming-book
And tutorials exist en masse.
My main points of inquiry are: Zend Framework - Why? Is it akin to JQuery for Javascript just making regular tasks simple?
It's a collection of utility functions. It's also a Passive/Web-MVC framework, but foremost a utility and glue code library. Some people see it as extension of the PEAR repository (also many useful classes).
Variable declaration - I've read that PHP is a loose language but what are the pitfalls?
PHP handles undefined variables and NULL values quite well. Many developers use heaps of isset()
to check for value presence. For form processing that's usually uneeded because that's what PHP was designed for. Critical business logic might benefit from isset and type checking (is_int or is_string, is_array, etc.)
How to take advantage of this fact? General good practice structure guidelines.
Practice.
I often rely on letting PHP do the optimal thing. Oftentimes you should resort to typecasting however. For objects you can meanwhile use typehinting in methods and functions. Another uncommon but advisable idiom is assert(is_array($param1));
In C# I can create multiple classes and reference those in my Code Behind using statements. Should I apply the same principle to PHP and just include the PHP files on the pages as needed or is there a better method?
There are multiple options. The include as needed approach is very workable for small and midsize applications. Many people rely on autoloaders for class structures, which simplifies the usage tremendously. Personally I use a central configuration file and dependency manager; loading all at once to save initialization time (but waste memory).
for learning php you should go for PHP Objects, Patterns and Practice (Expert's Voice in Open Source).
Use php manual for every doubt that you may have.
Also the advantages of zend framework are immense.It's ability to lets you pick and choose the components which makes it a very convenient for whatever project you are working on, new or old.Its more of a library then a framework.
You are going to find that PHP is a much closer cousin to VBScript (ala classic ASP) than to asp.net. That said, a number of the frameworks available can get it close to being what MVC is to .Net.
One of the best ways to translate your knowledge is to remember a few simple things. First, it is by no means a statically typed language; this can be a good thing and a very bad thing depending on how you look at it. Second, it is NOT compiled (unless you work for FaceBook). Third, in .Net we can easily build complicated class heirarchies and trust the compiler to ensure compliance; in php you might want to keep things a bit more flat.
Next, php.net is your best friend; learn to use it wisely. Your second best friend is going to be the echo statement.
Finally, just to iterate the point, as a c# developer we depend heavily on our compiler to block deployment and give us nice warnings about the mess we are about to step in. In a php world you no longer have this safety net.
As i was picking up PHP W3school's PHP page helped me VERY much.
精彩评论