On the ProDevTips blog, Henrikshows an example of the "perfect combination" of PHP's json functionality and a powerful javascript library, jQuery.
Today I looked for a replacement for my old jspanserializer.js script that I can't even remember where I found anymore. Turns out that I wont have to either, I can forget it. From now on I'll use jQuery JSON instead.
A code example is included to show the simplicity.
The NETTUTS.com website has a new tutorial posted that combines PHP and AJAX (using the the jQuery library specifically) to create a simple dynamic poll.
When you combine some neat functionality courtesy of PHP with the cleverness of jQuery you can produce some pretty cool results. In this tutorial we'll create a poll using PHP and XHTML, then make use of some jQuery Ajax effects to eliminate the need for a page refresh, and to give it a nice little bit of animation.
The PHP handles defining the question, answers and the functionality to load, submit and return the current results (number of votes) back to the javascript. The communication between the PHP and javascript is a JSON message made simple thanks to PHP's json_encode function.
Henrik continues his look at fluent arrays and strings in PHP with this second part of his series, adding JSON functionality into the mix.
Recently I've had the need to extend the interface further, among other things with JSON support. I've used code published by Nicolas Crovatti to do this.
His example shows how the script works to plot out some points for a table of stats. He follows this with an in-depth look at the different methods making up that fluent call (apply2Field, fill_ret, sum and plot). These make the array that can then be passed off to PHP, using json_encode to make an easy-consumable JSON message out of the results.
Jake Blauzier has just posted the last part of his series focusing on the creation of an event-based Ajax framework that works with PHP. It allows for calls to static functions, can return Javascript representations of PHP objects and a "call queue" system to keep things from overlapping.
Brian Moon has a "stupid PHP trick" posted to his blog today - normalizing SimpleXML data you've pulled in from just about any external source.
Anyhow, one annoying thing about SimpleXML has to do with caching. When using web services, we often cache the contents we get back. We were having a problem where we would get an error about a SimpleXML node not existing.
They were using memcache to store the information but came across problems when their code tried to use a (sometimes) empty tag. He gives two solutions - one using a recursive function that identifies the empty items and the other that encodes then decodes the object to and from JSON, keeping the values intact.
Marco Tabini has posted his list of what he considers five features of PHP5 that you "can't afford to ignore" when doing your development work:
Despite the fact that you may not have a choice in the matter, upgrading comes with a number of bonus new features that can help you write better code and gain access to new functionality that required a fair amount of hacking in previous version. Here's a quick list of 5 personal favourites.
The feature to make his list are SimpleXML, JSON/SOAP, PDO, the Standard PHP Library and SQLite. Each has their own bonus feature(s) included too for a little extra incentive to check them out.
Michael is back with part three of his series stepping you through the creation of your own MVC framework (Part 1 and Part 2) with a look at the part that interfaces with the user - the View.
Using the view as a starting point may seem odd at first considering the view-related actions are some of the last steps in the page load scenario, but since our views don't have any external dependencies, unit tests are very easy to write and so is the accompanying code.
He explains how views work along with the rest of the framework and some of the basic rules surrounding how they get their data. Code comes along with the explanations for different views like XML, HTML and JSON methods of output.
In dealing with a little JSON encoding and objects in a project of his recently, Cal Evansbumped against a problem when he was encoding an object and moving it back and forth between the back and front ends.
The problem is simple, JSON encode a PHP object and send it back to the front end. Sounds simple and the last 100 times I wrote this code it was simple. This time, I was too smart for my own good. Here's the scenario.
He illustrates his problem - the "dropping" of properties somewhere along the way - with a sample class that encodes the object and sends it along. He missed one key bit of information, though. His protected array of properties wasn't getting passed back out correctly and we're in the resulting JSON message. A quick hack of a getProperties() function call made this problem a thing of the past.
In a new post to his blog today, John Coggeshall comments on some thoughts from Alan Knowles about a method for making PHP obsolete.
Alan, I think you were smoking way too much PHP when you wrote this post.. This in particular really surprised me to hear you say [that a module that made mysql stored procedure calls based on a URL and returned JSON could make PHP obsolete]. While I do understand the concept your explaining, I simply can't see how the model is practical at all for two big reasons.
His reasons involve not having a business case where an entire application is right there for the user to download and that its an insecure method for running an app.