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

Lorna Mitchell's Blog:
PHP Returning Numeric Values in JSON
Jul 12, 2011 @ 13:41:39

Lorna Mitchell has a quick reminder about an issue in the new joind.in API version - everything was being returned as strings, even integers.

A few weeks later (my inbox is a black hole and it takes a while to process these things) I fell over a throwaway comment to an undocumented constant JSON_NUMERIC_CHECK, and I added the constant name to my todo list. In the time it took for me to actually get around to googling for this, some wonderful person updated the PHP manual page (this is why I love PHP) to include it as a documented option, and someone else had added a user contributed note about using it.

This option, JSON_NUMERIC_CHECK, tells the json_encode function to property consider numbers in its encoding process. It applies globally, so if there's an instance where you don't want something assigned as a number, you might need to go with another, more flexible JSON encoding option. You can find information about this and other possible options json_encode can take on its manual page.

tagged: jsonencode numeric integer string return encode jsonnumericcheck

Link:

Evert Pot's Blog:
Numeric string comparison in PHP
Apr 26, 2011 @ 14:23:47

In this new post to his blog Evert Pot reminds you (the PHP developer) about the loose and strict typing checks that you need to do when checking the values of your variables and never just assume. PHP's loose typing tendencies can cause issues if you're not paying attention.

As long as you make sure you always use strict checking (=== and !==) where you can, and fall back to the loose checks when you must. As a PHP developer, I think it's very important to understand and memorize exactly how these work, whether you're writing new code, or maintaining existing code.

He points out a specific example of some code that seems counter-intuitive when you compare how it reads and how it actually works (strings converted to floats and evaluated)

The moral is: always do strict checks when you are able to.
tagged: numeric comparison evaluate loose typing typecheck

Link:

Ilia Alshanetsky's Blog:
Type hinting for PHP 5.3
Jul 02, 2009 @ 14:46:18

One of the features included in the PHP 5.x releases is type hinting for validating that you have the right values for your functions and methods coming in. In this new post to his blog Ilia Alshanetshy takes a look at the the feature and gives a patch to add it .

On a general level most people agree it would be a good idea to have, since it is an optional feature and does not introduce any regressions, heck you can even mix type hinted code with the non-type hinted one. The "PROBLEM" has always been combining of PHP's typeless nature with type hinting, which is where the consensus has been difficult (impossible) to reach.

He mentions an example of why its such an issue (technically, both 1 and "1" are valid numbers) and includes a link to a patch that gives a new hint to help with the problem.

tagged: patch scalar numeric typehinting

Link:

Mind Tree Blog:
Friendly URLs in PHP: why do you care?
Jun 26, 2008 @ 15:26:59

This new post from the Mind Tree blog (at hurricanesoftware.com) asks the question "why do you care about friendly URLs in PHP applications?"

Nice URLs, readable URLs, search-engine-friendly URLs. Different names same deal. [...] Turns out this isn't all that hard with PHP - in fact it can turn into something that's very useful from more than just a readability viewpoint.

He shows how to use mod_rewrite and an .htaccess file to automatically grab the request and map it to the right place. Then, the PHP script looks at the incoming data and pushes the correct page back out to the browser. He's also included some modifications to the original idea that allow for numeric grouping and named groups for rewriting content.

tagged: friendly url modrewrite htaccess group named numeric

Link:

DevShed:
The Switch Statement and Arrays
Jan 07, 2008 @ 18:50:00

DevShed continues their series looking at some of the fundamentals of working with PHP in this new tutorial posted today. It looks at one of the flow control statements the language has to offer and a very useful data structure - the switch statement and arrays.

In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.

They start with a simple example of a switch statement (to echo out strings) and follow it with a detailed description of the different sorts of arrays - numeric indexed, associative and multidimensional versions.

tagged: tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional

Link:

DevShed:
The Switch Statement and Arrays
Jan 07, 2008 @ 18:50:00

DevShed continues their series looking at some of the fundamentals of working with PHP in this new tutorial posted today. It looks at one of the flow control statements the language has to offer and a very useful data structure - the switch statement and arrays.

In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.

They start with a simple example of a switch statement (to echo out strings) and follow it with a detailed description of the different sorts of arrays - numeric indexed, associative and multidimensional versions.

tagged: tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional

Link:

DevShed:
The Basics of Using the Factory Pattern in PHP 5
Jun 26, 2007 @ 16:07:00

DevShed revisits its series on using design patterns in PHP applications with this new tutorial, a look at implementing the Factory pattern in PHP 5.

Summarizing, the factory pattern can be really useful when it comes to creating multiple objects that belong to the same family. In this three-part series I'm going to take a close look at it, and also demonstrate its remarkable functionality by showing you a decent variety of code samples, so you can start quickly including this pattern into your own PHP applications.

They lay the foundation by creating some basic factory classes for working with numeric and associative arrays. On top of this, they create the processing classes to create things like uppercase numeric arrays and lowercase associative arrays. Finally, they give examples of how to put it to use making several different sorts of arrays, including their output.

tagged: factory designpattern php5 tutorial array associative numeric factory designpattern php5 tutorial array associative numeric

Link:

DevShed:
The Basics of Using the Factory Pattern in PHP 5
Jun 26, 2007 @ 16:07:00

DevShed revisits its series on using design patterns in PHP applications with this new tutorial, a look at implementing the Factory pattern in PHP 5.

Summarizing, the factory pattern can be really useful when it comes to creating multiple objects that belong to the same family. In this three-part series I'm going to take a close look at it, and also demonstrate its remarkable functionality by showing you a decent variety of code samples, so you can start quickly including this pattern into your own PHP applications.

They lay the foundation by creating some basic factory classes for working with numeric and associative arrays. On top of this, they create the processing classes to create things like uppercase numeric arrays and lowercase associative arrays. Finally, they give examples of how to put it to use making several different sorts of arrays, including their output.

tagged: factory designpattern php5 tutorial array associative numeric factory designpattern php5 tutorial array associative numeric

Link:


Trending Topics: