 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Sherif Ramadan: A Closer Look Into PHP Arrays What You Don't See
by Chris Cornutt October 29, 2012 @ 11:43:33
In a new post Sherif Ramadan takes an in-depth look at PHP arrays and what happens behind the scenes when they're put to use.
PHP is one unique language where the array data type has been highly generalized to suit a very broad set of use cases. [...] I'm going to share with you some of the underlying details of how the PHP array data type works, why it works the way that it does, how it's different from other languages, and what behaviors the PHP array has that you may not be fully aware of.
He starts with a section looking at what arrays actually are in PHP (and how they compare to the lower level C arrays). He gives a C-based array example and shows how it's stored in memory. He points out how PHP arrays are different from other languages and shows the C code that works behind the scenes to create the array (actually a hashtable). He gets into a detailed explanation of the iteration of arrays including some basic benchmarks of some of the various methods and gets more in-depth with foreach (including subarrays and arrays containing references).
voice your opinion now!
array language c hashtable indepth variable
DZone.com: How to correctly work with PHP serialization
by Chris Cornutt August 29, 2012 @ 08:19:37
In this new post to DZone.com today Giorgio Sironi takes a look at the serializing functionality in PHP and how it works with both regular variables and objects.
PHP is able to automatically serialize most of its variables to strings - letting you save them into storage like $_SESSION. However, there are some tweaks you have to know to avoid exploding .php scripts and performance problems.
He gives some code snippets showing the serialization of variables and objects and points out a few things that can't be effectively serialized (like resources and closures). The mentions the "__sleep" and "__wakeup" magic methods for automatic class serialization and mentions the Serializable interface that comes built in to PHP.
voice your opinion now!
serialize variable object tutorial sleep wakeup serializable interface
Gonzalo Ayuso: How to use environ variables to create different environments with PHP
by Chris Cornutt August 27, 2012 @ 07:49:29
Gonzalo Ayuso has a new post to his site showing how you can set up and use environment variables to make different environments for your applications.
If you use a framework such as Symfony2 this problem is solved for you, but if you aren't using any framework you probably need to solve it in one way or another. [...] The solution that I like for this kind of problem [with having different environments] is to use apache's environ variables. We inject the environ variables in the virtual host configuration.
He shows how to add a variable to the VirtualHost section of your Apache config, how to use the getenv function to retrieve its value and how to use it to select a configuration set. This method can also be applied to other kinds of information including settings you may not want to hard-code directly in you app (like possible database credentials).
voice your opinion now!
environment variable apache configuration tutorial
Evan Coury: Environment-specific configuration in Zend Framework 2
by Chris Cornutt July 19, 2012 @ 11:36:06
Evan Coury has a new post looking at setting up environment specific configurations in a Zend Framework 2 application letting you switch between configs based on an environment variable.
So you're all excited to try out ZF2. You clone the skeleton, install some modules, maybe even follow Rob Allen's excellent ZF2 tutorial, and finally, start building your application. Now, if you're a former ZF1 user or refugee from another framework, you might be troubled at this point by the fact that, at first glance, ZF2 doesn't appear to take into consideration environment-specific configuration values (e.g., development, testing, staging, production). Luckily, this is not the case!
He includes a bit of sample code showing how you can use a simple getenv call to pull in the value from an "APPLICATION_ENV" environment variable and put it into an autoload path.
voice your opinion now!
zendframework2 environment config variable getenv
Anthony Ferrara: The Anatomy Of Equals - Opcode Analysis
by Chris Cornutt July 19, 2012 @ 10:11:48
Anthony Ferrara has a new post today getting into the details of how "equals" works in PHP at the opcode level. He focuses on the answer to a question he received:
I was asked an interesting question via email yesterday. The question is fairly simple. The answer, not so much... So, rather than reply in an email, I figured that I'd write a post about it instead. The question, simply stated, is: "When comparing a float to an integer using ==, where does the conversion happen?"
He starts with a super simple piece of test code that compares an integer (1) to a float (1.0) and walks through the process PHP takes to perform the comparison (with a double equals "=="). He talks about opcode handlers, the "fast equal function" and how it handles the casting from one type to another, C source highlights included.
voice your opinion now!
equals opcode source language cast variable
PHPClasses.org: The Secret PHP Optimization of version 5.4
by Chris Cornutt June 14, 2012 @ 12:12:42
In this new post from Manuel Lemos on the PHPClasses.org blog about some of the performance enhancements that were introduced in the latest PHP releases (the 5.4.x series) including variable access optimization.
PHP 5.4 introduced several performance optimizations. One of them was not discussed much in the PHP community but it may affect the performance of your code depending on the way you write it.
He gets into some of the details surrounding the variable access optimization, pointing out how to get the most out of this improvement. He also does a bit of speculation about future versions of the language, including the possible introduction of "Just In Time" compilers.
voice your opinion now!
optimization version variable access object property
Project: Patchwork-Doc - JSON Formatted Output of PHP variables
by Chris Cornutt October 06, 2011 @ 12:16:58
Nicolas Grekas has submitted about a new tool he's developed to "represent faithfully any PHP variable as complex as it is" - Patchwork-Doc (related to his Patchwork PHP framework).
The JSON format on which it rests guarantees maximum interoperability while ensuring good readability. The implementation done in the JsonDumper class operates all potentialities of the representation while providing maximum latitude to the developer to exploit its ability as desired, both in term of exposure of internal class mechanism for specialization and in terms of custom use, thanks to the callbacks that allow to intercept the JSON line by line and to adjust the dumping of objects or resources according to their type.
It isn't required to use the framework to use this tool, however. You can see an example of the output format in this example on the project's github page, complete with a guide to some of the advantages and disadvantages of some of the current, more common methods of output. Several types are included in the example including simple string/integer values, objects, classes, stream resources and the results of variable casting.
voice your opinion now!
patchworkdoc output variable json encode framework patchwork
Gonzalo Ayuso's Blog: Reflection over PHPDoc with PHP
by Chris Cornutt April 04, 2011 @ 12:51:15
Gonzalo Ayuso has a new post to his blog today talking about a regular expression-laden script he's some up with to reflect over a PHP file and pull out the document's comments (PHPDoc-style).
I want to parse PHPDoc code. Let me explain a little bit what I want to do. Imagine a dummy function documented with PHPDoc. [...] PHP has a great reflection API, but as at least in the current PHP version (as far as I know) we only can get the PHPDoc as a string, without parse it. I need to get the parameters and the type of them with reflection. [...] But the type is different.
His script (based loosely on a bit of a component from the Zend Framework) parses the file and its comments and grabs the variable types from the PHPDoc blocks on each method and associates them.
If you're looking for a more mature solution than just this script, take a look at Docblox, a PHP 5.3 documentation generator.
voice your opinion now!
reflection tutorial phpdocumentor comment variable type
Derick Rethans' Blog: Debugging Variables
by Chris Cornutt February 10, 2011 @ 09:26:18
Derick Rethans has a new post to his blog today looking at a way you can dig inside of a variable that might be causing you trouble with the help of the debug_zval_dump method - a PHP function that dumps a string representation of an internal zend value directly to the standard output method (usually an "echo").
The internal representation of a PHP variable container (called zval), contains the type and value of a variable, but also whether it is a reference and what its refcount is. Due to PHP's copy-on-write policy, one specific zval container can be used by multiple variables at the same time as we will see in a bit.
He talks about what the "refcount" field of a variable means and some simple examples showing a single reference, more than one symbols and how PHP handles a "split upon assignment". He also mentions Xdebug's method xdebug_debug_zval that takes in a variable name rather than the variable itself.
voice your opinion now!
debug variable debugzvaldump tutorial
|
Community Events
Don't see your event here? Let us know!
|