Tuesday, May 31, 2016

PHP: Knowing the Basics

PHP (recursive acronym for PHP: Hypertext Preprocessor) is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more.[1]

PHP has the following features:
  • PHP code may be embedded into HTML code
  • PHP code is usually processed by a PHP interpreter 
    • PHP interpreter is implemented as a module in the web server or as a Common Gateway Interface (CGI) executable. 
    • The web server combines the results of the interpreted and executed PHP code, which may be any type of data, including images, with the generated web page. 
  • PHP code may also be executed with a command-line interface (CLI) 
    • Which can be used to implement standalone graphical applications.

Pros and Cons


Based on an article posted in 2010, here are the pros and cons described by 8 experts: [2]

Pros
  • Ubiquity and ease to use
    • With PHP, you have the freedom of choosing an operating system and a web server.
  • An excellent tool for disciplined developers
    • It stays close to its C roots while removing some of the unnecessary pain points like memory management, pointers and the compile cycle. 
    • The OOP implementation is simple, elegant and easier to read than its peers. 
    • The Java mantra of "complexity at any cost" is nowhere to be found; concise method names are used throughout. 
  • Good documentation 
  • Healthy PHP community
    • PHP Planet is a great resource for and from PHP community members

Cons
  • One of PHP's biggest strengths is also one of its limitations
    • Hard to maintain codes written by other people
      • PHP is very flexible in general; there are no less than 30 ways to accomplish the same task.
      • Especially when code standards are not consistent and best practices aren't followed
    • Lots of bad PHP in the world
      • The low entry barrier means that there is a lot of bad PHP in the world
      • The readily available resources online can be great and terrible at the same time
        • For example, junior developers can quickly pick up insecure PHP codes from the Internet and adapt them in their projects
    • Too much choice (time can be wasted searching for quality codes)
      • Developers have too much choice when it comes to selecting a library or framework to work with, and the information available is often biased and unreliable so a lot of time can be wasted searching for quality.

PHP Composer


If you have ever written anything in PHP before, you have probably found that it feels like you have to keep re-inventing the wheel anytime you want to do a common task such as User Authentication, Database Management or Request Routing. PHP now has a dozen of mature frameworks[10,11]
that have already solved all of these problems.  PHP Composer is a tool to make it easier to cherry pick the bits that you needed from each framework.

To summarize, PHP Composer is
  • A dependency manager for PHP
    • Help you to install packages on a project-by-project basis

References

  1. What can PHP do?
  2. 8 Experts Break Down the Pros and Cons of Coding With PHP
  3. HipHop
  4. PhpUnit
  5. Joind.in
    • Is a good example of a PHP app
  6. StatusNet
    • Is an open-source microblogging platform
  7. PHPDoc
  8. Facebook
    • Best PHP application dealing with scalability
  9. What is PHP Composer?
  10. The Best PHP Framework for 2015: SitePoint Survey Results
  11. 10 PHP Frameworks For Developers – Best Of
  12. PHP Extension and Application Repository (PEAR)
    • Is a repository of PHP software code to promote the re-use of code that performs common functions (founded by Stig S. Bakken in 1999)
  13. PHPClasses.org
    • Is a service created in 1999 as a means of distributing freely available programming classes of objects written in PHP
  14. Software Collections (rh-php56)