Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Toptal.com:
Clean Code and The Art of Exception Handling
Apr 13, 2016 @ 14:43:50

While not specific to PHP (the examples are in Ruby, in fact) this new tutorial on the Toptal.com blog has some good information and suggestions around the use of exceptions in your applications.

Exceptions require special treatment, and an unhandled exception may cause unexpected behavior. The results are often spectacular.

Over time, these errors, and countless others [...] contributed to the impression that exceptions are bad. But exceptions are a fundamental element of modern programming; they exist to make our software better. Rather than fearing exceptions, we should embrace them and learn how to benefit from them. In this article, we will discuss how to manage exceptions elegantly, and use them to write clean code that is more maintainable.

They start by talking about why exception handling is a good thing and some common practices to help make them more manageable. They suggest that good exception handling can also help make your code more maintainable, extensible and readable in the long run. He suggests creating your own kind of exception hierarchy (more possible in PHP 7) and using them to get more specific on the type of exception that was thrown. He recommends not "rescuing" exceptions more than needed (in PHP this is try/catch) and that it's okay to defer the handling for the exception being thrown and not deal with it right away.

He also reminds you that not all exceptions need handling in your own code (sometimes it's up to the user) and that following conventions on naming can help end users better understand why there's an error. Finally, he recommends logging exceptions as they're major errors in your application, not just data problems or smaller bugs.

tagged: clean code exception handling bestpractice hierarchy trycatch convention

Link: https://www.toptal.com/qa/clean-code-and-the-art-of-exception-handling

Davey Shafik:
Changes to Engine Exceptions in PHP 7.0alpha2+
Jul 06, 2015 @ 14:41:29

Davey Shafik has posted about some changes in engine exceptions in the latest alpha of PHP 7 (alpha2+), mainly a small change to how things are named.

While updating my PHP 7 talk “What to Expect When You’re Expecting: PHP 7″ for the DutchPHP Conference 2 weeks ago I noticed a small but significant change to the new Engine Exceptions feature in the newly release alpha 2. [...] However, for alpha2 this hierarchy changed. Engine Exceptions lost their “Exception” suffix, and became Error and and *Error exceptions, and the abstract BaseException class was changed to a Throwable interface.

He points out that this new naming and structure makes it impossible to make a good hierarchal structure for exceptions. He does favor the new format, though, as it does allow for some structure via interface definitions.

tagged: exception handling php7 alpha2 throwable handling hierarchy

Link: http://daveyshafik.com/archives/69185-changes-to-engine-exceptions-in-php-7-0alpha2.html

Giorgio Sironi's Blog:
The dangers of Late Static Bindings
Apr 14, 2010 @ 12:06:41

Giorgio Sironi has a new post that warns you of the dangers that could come from the use of a technology just recently introduced to PHP - late static binding.

There's a lot of (justified) excitement about PHP 5.3 new features, such as the support of namespaces and anonymous functions. Though, some glittering capabilities of the language are definitely not gold: the goto statement is probably the most debated example, but also the long-awaited Late Static Bindings support is an hammer which may hurt your fingers...

He talks about how two of the characteristics of late static binding - the fact that it involves something being static and that there's a sort of hierarchy involved. He gives a code example of how it could be used and notes that static functions should be used sparingly since they are a more procedural way of doing things.

The post also includes a good example - an abstract Factory method - and a bad example - Active Record that doesn't evolve towards a Repository pattern being used.

tagged: latestaticbinding danger procedural static hierarchy

Link:

Brandon Savage's Blog:
Marketing for PHP Developers
Apr 01, 2009 @ 14:34:16

Brandon Savage has a new look at an old problem in the PHP community - the importance of a developers' understanding of marketing in applications.

Technical people seem particularly bad at marketing effectively. I think this is because we’re fact-oriented, focused on the features and neat ideas our products include. We’ll spend pages and pages talking about the cool things that our tool or application can do. And then we’ll wonder why our client didn’t buy it. Why do we do this? Because we forget that marketing isn’t about features it’s about meeting needs.

He points to the hierarchy of needs as an example of what really has to be considered when developing software. The further down the pyramid you and your software can go, the more effective your marketing can be. An application can do everything under the sun, but if it doesn't do what the customer wants, it'll be tossed aside.

tagged: marketing developer need want pyramid hierarchy

Link:


Trending Topics: