Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PHP


  Using JSON in PHP

Currently JSON has become one of the most popular data exchange formats. Many website APIs support it. Since PHP 5.2, PHP provides json_encode() and json_decode() method to handle JSON encoding and decoding.1. json_encode()This function is used to transform array and objects to JSON format. First let's look one array example.        $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);   echo json_encode($arr);the result is{"a":1,"b":2,"c":3,"d":4,"e":5}We look one example of object transformation.      ...

15,468 1       PHP JSON JSON_DECODE(0 JSON_ENCODE()


  How to send asynchronous requests in PHP

It’s easy to make asynchronous calls in PHP with just a little bit of HTTP header knowledge and some library code around PHP sockets.This technique is useful when posting requests to your own server for bits of logic you’d like to run in the background.  If you don’t control the endpoint, you might not be comfortable with some of the limitations, such as the inability to read anything from the response.  So, you couldn’t post data to a webservice and receive an HTTP 200 OK response and certainly not an ID for an object newly created by the serv...

7,874 0       PHP SOCKET ASYNCHRONOUS REQUEST


  PHP Sucks! But I Like It!

I read a rather interesting post yesterday called PHP: a fractal of bad design. It's been getting a lot of traffic among the PHP community lately because it's rather inflammatory. But to be honest, it does make a lot of really good points. It also makes a lot of mistakes and misses a bigger picture.A Few MistakesThe post makes quite a few mistakes and odd apples to oranges comparisons. Let me point out the major ones that I saw.No Debugger - PHP has xdebug which works quite well as an interactive debugger.Lack Of Threading - This is true, but he lists it as a difficulty, and I list it as ...

19,084 0       PHP LIKE BAD DESIGN


  PHP: a fractal of bad design

PrefaceI’m cranky. I complain about a lot of things. There’s a lot in the world of technology I don’t like, and that’s really to be expected—programming is a hilariously young discipline, and none of us have the slightest clue what we’re doing. Combine with Sturgeon’s Law, and I have a lifetime’s worth of stuff to gripe about.This is not the same. PHP is not merely awkward to use, or ill-suited for what I want, or suboptimal, or against my religion. I can tell you all manner of good things about languages I avoid, and all manner of b...

18,609 2       PHP DESIGN ANALYSIS


  40+ Techniques to enhance your php code

1. Do not use relative paths , instead define a ROOT pathIts quite common to see such lines :1require_once('../../lib/some_class.php');This approach has many drawbacks :It first searches for directories specified in the include paths of php , then looks from the current directory.So many directories are checked.When a script is included by another script in a different directory , its base directory changes to that of the including script.Another issue , is that when a script is being run from cron , it may not have its parent directory as the working directory.So its a good idea to have absol...

4,156 0       PHP EFFICIENCY QUIRK TRICK TECHNIQUES


  PHP to get access token for Facebook app

Since Facebook is now using OAuth 2.0 to authenticate apps to access user information. the SDK of Facebook has provided developers some useful functions to get authentication done. For example, in PHP SDK, there are getAccessToken(), getLoginUrl() etc. But unfortunately, for me I cannot use getAccessToken() method to get the user access token, it only returns me the app access token. Finally I gave up this approach to get access token for the time being. I may later retry this approach if I have time.Today I show you another way to get the access token, which is explained on Facebook's develop...

29,117 4       PHP ACCESS TOKEN FACEOOK SIGNED REQUEST


  Understanding PHP's internal function definitions

Welcome to the second part of the “PHP’s Source Code For PHP Developers” series.In the previous part ircmaxell explained where you can find the PHP source code and how it is basically structured and also gave a small introduction to C (as that’s the language PHP is written in). If you missed that post, you probably should read it before starting with this one.What we’ll cover in this article is locating the definitions of internal functions in the PHP codebase, as well as understanding them.How to find function definitionsFor a start, let’s try t...

14,210 0       PHP DEFINITION INTERNAL FUNCTION RATIONALE


  Handling Plugins In PHP

A common problem that developers face when building applications is how to allow the application to be "plug-able" at runtime.  Meaning, to allow non-core code to modify the way an application is processed at runtime.  There are a lot of different ways that this can be done, and lots of examples of it in real life.  Over a year ago, I wrote a StackOverflow Answer on this topic.  However, I think it deserves another look.  So let's look at some patterns and common implementations.Communication HandlersThese patterns are designed to handle communication between disjoint ...

2,341 1       PHP PLUGIN HANDLING