====== Porting code from other languages to PHP ====== There are a number of important factors which make PHP special, compared to statically typed, compiled languages like Java, C++ and C#. If you're coming from a background in those languages it's important to be aware that writing PHP applications in the style you're used to may result in applications which run like a slug. It's also important to understand the overall "nature" of PHP (with which _both_ the procedural and object oriented paradigms can be applied). First of all PHP is (unless you're using a script cache) interpreted and compiled at runtime (*big hint*). Loading every class your application will ever use for every page request is a bad idea, for example. Profile your code with [[Xdebug]] PHP does not enforce the notion that everything is an object. Successful PHP applications mix both procedural and object oriented logic. Developers from Java background, for example, often begin by writing a class "Object" then extended it with all classes. That's already overhead you'll likely regret. It's important to use PHP in the "sense" it was designed to be used, which is a mix of both paradigms. Related to MVC, this _may_ mean you implement the Model (and below) as classes while the Controller and View are procedural. Being dynamically typed PHP, offers great flexibility but there's no compile time type testing. Unit testing is critical to success - there are a number of PHP Unit test frameworks, a very good choice being [[SimpleTest]]. Compile time type tests are arguably a subset of Unit testing anyway: see [[http://mindview.net/WebLog/log-0025|Strong Typing vs Strong Testing]]. PHP is (arguably) not a framework. Certainly it is a "lower level" framework than J2EE or .NET. Check out MvcFrameworksWrittenInPhp. PHP does not have a standard class library. PHP does have a large library of functions which deliver similar functionality to the fundamental classes and _some_ of the architectural classes common to Java and .NET. Being functions though, they are not cohesive. There are numerous packages freely available as Open Source, many gathered under repositories like [[PEAR]] and [[http://www.phpclasses.org|phpClasses]]. Some frameworks such as [eZPublish] and [Binarycloud] also pack rich class libraries. In general standards vary as does cohesiveness but for architectural issues, most problems have been well solved in PHP. A prime example is [[http://phpmailer.sourceforge.net|phpMailer]] which provides the necessary add ons to PHP's [[http://www.php.net/mail|mail()]] function. A discussion which may help you avoid making mistakes in advance is [[http://www.sitepointforums.com/showthread.php?threadid=116878|Java API as base for PHP library?]]. Regarding [[pattern:Model View Controller]], implementing a [[pattern:Front Controller]] in PHP may well be a bad idea. Many PHP frameworks pass all requests through a single script (e.g. index.php). Apache does a better job of serving web pages. PHP + Apache != Application Server. For more throughts [[http://www.sitepointforums.com/showpost.php?postid=794227&postcount=22|try here]]. PHP4's object model is basic. Solid OOP _can_ be written with PHP4 but developer self discipline is a requirement. Don't underestimate its potential. PHP5 addresses a lot of these issues [[http://www.sitepoint.com/article/1192|more info]]. Question is: [[http://www.sitepointforums.com/showpost.php?postid=869667&postcount=16|are Interfaces a good idea?]]. Consider the PHP [[php:Caching]] mechanisms. PHP projects shouldn't fail. With PHP it's possible to prototype //very// quickly. Consider ShippingThePrototype. Develop PHP apps along many short lifecycles. Be [[Agile]] PHP has the tools you need, such [[phpDoc]], [[Phing]], [[SimpleTest]], [[Xdebug]] and [[Umbrello]] Other reads: * [[http://www.artima.com/forums/flat.jsp?forum=106&thread=7590&start=0&msRange=15|Typing: Strong vs. Weak, Static vs. Dynamic]] * [[http://www.daholygoat.com/rants_php_and_designpatterns.htm|(Not) Applying Design Patterns in PHP]] * [[http://phplens.com/lens/php-book/optimizing-debugging-php.php|A HOWTO on Optimizing PHP]] * [[http://otn.oracle.com/pub/articles/php_experts/rasmus_php.html|Do You PHP? - Rasmus Lerdorf]] - sums it up