 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
NetTuts.com: The Ins and Outs of PHP Exceptions
by Chris Cornutt October 14, 2011 @ 08:44:32
On NetTuts.com today there's a new tutorial showing you the "ins and outs" of using exceptions in PHP - throwing them, handling the result and integrating them into your error handling process.
Still returning false whenever a function in your program fails? In this article, we'll learn about PHP exceptions, and how you can use them to soup up your application's error handling.
The include some of the methods you can call on your exceptions (including getting the message, code, file, line and the results of a debug_backtrace right before it was thrown). Included is code to throw exceptions, catch them with a try/catch and using error codes as return values and extending them to fit your own needs.
voice your opinion now!
exception handling throw tutorial extend example
P
by Chris Cornutt May 30, 2011 @ 09:48:29
Lukas Smith has a suggestion for developers out there who get the idea to start messing with the order of the parameters of PHP objects/methods - play nice. His example is specifically with Exceptions.
This is just a short follow up to a recent tweet of mine. I have seen this repeatedly happen, even to top notch and usually very careful developers (*). I am not sure why this mistake happens so frequently, but quite often you see code that changes the parameter order for custom Exception constructors. I guess it's mostly because in these cases the developer wants to pass some magic parameters that contain the message (and potentially also the code).
He recommends that, if you really do need to change something like the order of the parameters, use something like a factory to handle the reorganization for you.
voice your opinion now!
extend reorganization factory designpattern
Ralph Schindler's Blog: PHP Component and Library API Design Overview
by Chris Cornutt January 19, 2011 @ 09:19:29
Ralph Schindler has written up a new post for his blog today looking at APIs and some things to consider when building them. These aren't the web service APIs you're thinking of - this is the interfaces your code uses to talk to it's own parts.
It's important to have a common understanding of the actual problem area. When we talk about names, we are really talking about the API. An API is a particular set of rules and specifications that a developer can follow to access and make use of the services and resources provided by another particular software program, component or library. Put another way, it is an interface between various software pieces and facilitates their interaction, similar to the way the user interface facilitates interaction between humans and computers.
He talks about the two different APIs you're usually building at the same time - a consumption API that is the method others use to consume it and the extension API, how the feature allows others to improve upon it. He shares his own API philosophy and a three tips he's learned along the way to make his APIs more robust:
- Adopt A Common Namespace & Class Naming Scheme
- Avoid Doing Too Much In the Constructor
- Avoid final And private
voice your opinion now!
component library api design opinion consume extend
AjaxRay.com: Extending Zend Form Element to create customized Phone number field
by Chris Cornutt September 02, 2010 @ 08:05:06
On the AjaxRay.com site today there's a new tutorial for the Zend Framework users out there with a library they can use to extend Zend_Form for custom phone number fields.
When taking Phone number as user input, we can worn users about phone number format by setting a hint/description and can validate using Regular Expression. [...] Now, if we try provide this feature in Zend Form, that's possible. We can create three individual Zend_Form_Element_Text objects and join there value together to make the phone number. But, in this case, validating them together is a hassle.
Instead of separate fields, the library they create makes it simple to handle them as a whole field. It works as a helper for Zend_Form and lets you set things like the separator between the text fields, a "format" string and a validator to apply to their fields (in the example code, it's the "digits" validator). Sample code is included to show you how it fits in your form.
voice your opinion now!
zendform extend phone number custom field tutorial
Andrey Hristov's Blog: Replacing mysqli's Connection, Result and Statement classes
by Chris Cornutt July 09, 2010 @ 10:31:03
On his blog today Andrey Hristov has a quick post that talks about two methods to extend the functionality that the mysqli extension offers in PHP with your own custom code.
Have you ever though about extending mysqli's classes. It's pretty simple to subclass the connection class mysqli. However, subclassing mysqli_result and mysqli_stmt is not so obvious, actually I though that it's even not possible. However, never say never! After discussing mysqli's OO interface for an hour yesterday [...] I found out how one can plug his own classes.
Two code examples are provided - one for extending the mysqli_result and the other extending the mysql_stmt class. You can find more about these and other classes the mysqli extension has to offer in this section of the PHP manual.
voice your opinion now!
replace mysqli connection result statement class extend
Richard Thomas' Blog: Solar Framework Shorts - Extending Solar's Page Controller
by Chris Cornutt October 06, 2009 @ 08:24:32
Richard Thomas has posted another "short" in his series looking at the features of the Solar Framework. This time he focuses on enhancing the base framework functionality by extending the Solar_Controller_Page class.
Solar's manual has a getting started section that walks you through setting up a basic app, This app extends "Solar_Controller_Page" which handles a lot of the backend work for you. As you get into your project you will find that pretty much every controller you have needs access to some basic structures and information, how can you ensure these are always available?
His example extends the Solar_Controller_Page to provide two model objects automatically to the rest of his application (as protected objects in the base class).
voice your opinion now!
solar framework extend page controller tutorial
Zend Developer Zone: Extending Zend Server GUI '" Data Cache Information
by Chris Cornutt September 11, 2009 @ 10:01:16
New in the Zend Developer Zone today is this post looking at the Zend Server GUI and how you can extend it to add in data from the Data Cache API.
As the GUI of Zend Server is based on the open-source Zend Framework, you can easily extend it. This article demonstrates how to integrate new functionality to Zend Server which makes it possible see the content and some meta information of cached items. For this example I use the Data Cache API from Zend Server, but in combination with the Zend Framework component Zend_Cache and its Zend_Cache_Backend_ZendServer_Disk backend adapter.
He steps through the creation of a new Zend_Cache object and an implementation of the Zend_Cache_Backend_Interface as well as making the new tab for the data to live under in the GUI. The interface is dropped in place and a view and model is added and your end result can look like this.
voice your opinion now!
extend tutorial zendserver zendframework cache
Stubbles Blog: Extending objects with new methods at runtime
by Chris Cornutt September 01, 2009 @ 09:05:46
On the Stubbles blog today Frank Kleine looks at a cool trick that the features of PHP 5.3 now make possible - extending objects at runtime by adding in new methods and functionality.
With the advent of PHP 5.3 adding new methods to an instance of a class at runtime becomes possible with PHP as well, using anonymous functions and a little bit of __call() magic.
He illustrates with a bit of code - defining the base class and using a __call method to catch any undefined method calls. Using this in conjunction with closures makes it possible to call the method internally, avoiding the usual error that could result from setting it like you would a class property.
voice your opinion now!
extend object closure call
Zend Developer Zone: Zend_Tool for the Developer
by Chris Cornutt January 15, 2009 @ 10:21:35
Ralph Schindler has a recent tutorial posted to the Zend Developer Zone site looking at how you can extend the Zend_Tool component of the Zend Framework to meet your needs.
In order to understand how to extend Zend_Tool, you need to know a few things about its overall structure. The whole of the system was built with extensibility in mind. Each of the major functional parts of the system are abstracted in such a way that its easy to not only extend, but to replace with completely separate implementations. [...] But for our first order of business, we'll demonstrate how to add new commands to the Zend_Tool system.
He dives into the details of the Zend_Tool internals (including the Manifest component, the Provider_Version and the Provider_interface) before getting into the example code of the actual extension. He makes the typical "Hello World" example and shows how, with a simple command line call, you can execute the provider.
voice your opinion now!
zendtool zendframework component extend tutorial
AskAboutPHP.com: CodeIgniter Extending the native 'Model' and make it your own.
by Chris Cornutt November 12, 2008 @ 09:31:24
The AskAboutPHP.com blog has posted a helpful new tutorial for those using CodeIgniter out there - how to extend the native Model class to bend it to your will.
I'm in the process of creating models for my CI project, and realized that certain functions within the models were getting repetitive. Using CI's ability to create my own custom libraries, I was able to create my own custom 'Model' which extends from the core 'Model' object. How this simple architecture has cleaned up my code is simply remarkable.
Rather than overwriting the main Model.php file with some of your own changes, he suggests creating a new library, a "parent model" that can be extended instead to provide some common functions that all of your application's models might need. For something a bit more complex, he also points to this library that extends the models to give it CakePHP-like functionality.
voice your opinion now!
codeigniter framework model extend custom parent library
|
Community Events
Don't see your event here? Let us know!
|