 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
DevShed: The Destruct Magic Function in PHP 5
by Chris Cornutt June 24, 2009 @ 08:46:18
DevShed has posted the second to last part of their tutorial series looking at the magic functions in PHP. This time they focus on the destruct function, a method that is fired off when an object is being removed from memory.
There are a few [other methods] that can be really useful for performing relatively complex tasks with a minimal amount of code. That's exactly the case with the "__destruct()" method, which will be called automatically by the PHP engine before destroying an instance of a particular class at the end of a script.
They update their example class with a new __destruct method that takes the user information inserted previously, serializes it and drops it into the current session.
voice your opinion now!
tutorial function magic destruct
DevShed: The Autoload Magic Function in PHP 5
by Chris Cornutt June 23, 2009 @ 07:56:57
DevShed has posted the latest article (the last) in their series looking at the "magic functions" that PHP has to offer. This time they take a closer look at the autoload functionality.
PHP 5 offers yet another magic method that can be extremely useful for loading classes automatically, without having to use explicitly any "include()/include_once()" or "require()/require_once()" function. As the article's title suggests, I'm talking specifically about the "__autoload()" function, which deserves a deeper analysis.
Their example shows how to define the __authoload method for your application to load in libraries as they're needed, without having to specifically define them.
voice your opinion now!
tutorial function magic autoload
DevShed: The Sleep and Wakeup Magic Functions in PHP 5
by Chris Cornutt June 17, 2009 @ 08:49:19
DevShed has posted the next part of their series looking at the "magic functions" that PHP5+ has to offer you in your development. They've already looked at ones like __call, __clone and __isset/__unset and now, with this new tutorial they've added __sleep and __wake.
Magic functions are an important part of the numerous improvements and additions that were introduced originally in PHP 5. They can be extremely handy when it comes to simplifying the execution of complex tasks. [...] In this fourth chapter I'm going to examine closely the "__sleep()" and "__wakeup()" functions, which are called automatically when an object is serialized and unserialized respectively.
In their example code they add the __sleep and __wake functions to the class they've been developing to output a string when the object is manipulated. These methods are automatically called when a serialize/unserialize function call is made on the object.
voice your opinion now!
tutorial function magic wakeup sleep
DevShed: The Call Magic Function in PHP 5
by Chris Cornutt June 09, 2009 @ 08:44:57
Continuing their look at the "magic functions" that are included in PHP5, DevShed has posted this new tutorial looking at the "__call" method to intercept calls to methods in a class that don't exist.
If you're a PHP developer who wishes to learn how to implement and use the set of magic functions that come included with PHP 5, you've come to the right place. [...] As the title of this article suggests, in the new few lines I'm going to take a deeper look at the"__call()" function, so that you can quickly become familiar with it.
They include code examples of the __call method in use - catching a call to a "fetch" method.
voice your opinion now!
tutorial call function magic
DevShed: Magic Functions in PHP 5
by Chris Cornutt May 27, 2009 @ 08:42:38
In this new tutorial on DevShed they take a look at a feature added in PHP5 to help makes developers' lives easier - magic functions. These magic functions (like __get and __set) can help you catch things a bit closer to the execution of the language than an if or other conditional could and to do some very fun things.
It's not breaking news that the release of PHP 5 drastically changed the way that many developers build their web-based programs. The incorporation of a much more robust object model, along with the introduction of native exceptions, type hinting and so forth (add your own improvement to the list) has given the language the maturity that we see in it today. This seven-part article series will explain an important new feature: magic functions.
This first part of the series looks at __get and __set and how to use them for property overloading in a class.
voice your opinion now!
tutorial function magic
Fabien Potencier's Blog: On PHP 5.3, Lambda Functions, and Closures
by Chris Cornutt April 17, 2009 @ 10:29:43
In this new post to his blog Fabien Potencier looks at two of the much-hyped features of the upcoming PHP 5.x series release (5.3) - closures and lambda functions.
I won't talk too much about what lambda functions or closures are, as you can find many good blog posts describing them in great details. To sum up, a lambda function is an anonymous PHP function that can be stored in a variable and passed as an argument to other functions or methods. A closure is a lambda function that is aware of its surrounding context.
He includes several examples including how they would work with a few of the array functions, an implementation of the Y-combinator method (as written by Stanislav Malyshev) and how they can be used to create dependency injection functionality.
voice your opinion now!
lambda function closure php5 array ycombinator dependency injection container
Packt Publishing: PHP Magic Features
by Chris Cornutt April 14, 2009 @ 09:31:48
Packt Publishing has posted a new article from Jani Hartikainen about the "magic methods" that PHP comes with - methods, properties and constants really.
Magic methods, which are class methods with specific names, are used to perform various specialized tasks. They are grouped into two: overloading methods and non-overloading methods. [...] Magic functions, which are similar to magic methods, but are just plain functions outside any class. [...] Magic constants, which are similar to constants in notation, but act more like "dynamic" constants. We'll also look at some practical examples of using some of these, and lastly we'll check out what new features PHP 5.3 is going to add.
He looks at the various functions/methods and constants (like __clone, __toString), some of the overloading methods like __call, and magic constants like __FILE__ and __CLASS__. He wraps it up by briefly discussing what PHP 5.3 adds in - a few new magic methods and constants (but no functions).
voice your opinion now!
magic features php5 constant function method
Benjamin Eberlei's Blog: Test your Legacy PHP Application with Function Mocks!
by Chris Cornutt March 31, 2009 @ 11:18:31
Benjamin Eberlei has a suggestion for testing your application without having to mess around with creating new resources just for testing - use mocks.
Much talking is going on about Unit testing, Mocks and TDD in the PHP world. For the most this discussions surround object-oriented PHP code, frameworks and applications. Yet I would assert that the reality for PHP developers (me included) is dealing with PHP 4, PHP 5 migrated, or non-object oriented legacy applications which are near to impossible to bring under test.
He includes a "proof of concept" for a replacement mysql_query function (as created inside of Runkit) that sets up a "mocker" object that returns a "hello world" message when the mysql_query function is called.
voice your opinion now!
mock function runkit proofofconcept mysqlquery resource
DevShed: Tracking a Stack of Function Calls with the Xdebug Extension
by Chris Cornutt March 16, 2009 @ 13:14:19
On DevShed today the latest article in their XDebug series has been posted, a look at tracking the function call stack with help from functionality the extension provides.
Despite this inconvenience [pf not being able to get more in-depth], in this final part of the series, I'm going to show you how to work with a function of the library called "xdebug_get_function_stack()." This function can be used to keep track of the stack of function calls generated by a PHP script, in this manner completing this starting guide on this helpful extension.
After reviewing the script from the previous part (using xdebug_time_index) they get into this new function and what sort of output it provides. The stack is the trace of what functions and values were passed around in the script including information like the function name, parameters and the file it was in.
voice your opinion now!
track stack function trace xdebug extension tutorial
|
Community Events
Don't see your event here? Let us know!
|