News Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
How to Use the JsonSerializable Interface
May 05, 2014 @ 11:50:28

Matrin Hardy has a new tutorial posted to the SitePoint PHP blog today showing you how to use the JsonSerializable interface to work with objects and converting them to JSON.

Over the past few years JSON has taken over as the king of data interchange formats. Before JSON, XML ruled the roost. It was great at modeling complex data but it is difficult to parse and is very verbose. [...] I think we could all agree that writing less code that in turn requires less maintenance and introduces less bugs is a goal we would all like to achieve. In this post, I'd like to introduce you to a little known interface that was introduced in PHP 5.4.0 called JsonSerializable.

He splits the rest of the post out into three different parts: the "ugly" method of converting a sample Customer object into a JSON string (through an array), the "bad" method using a "toJson" method and finally the "good", implementing a class that implements the JsonSerializable interface for easy JSON-ification.

0 comments voice your opinion now!
jsonserializable interface tutorial introduction beginner

Link: http://www.sitepoint.com/use-jsonserializable-interface/

SitePoint PHP Blog:
Using Solarium with SOLR for Search - Setup
May 02, 2014 @ 11:49:16

The SitePoint PHP blog has posted a tutorial showing you how to use the Solarium library to search SOLR. Solarium is a PHP-based, open source tool that helps make interfacing with a SOLR search instance much easier. This post is part one of a larger series covering the combination of SOLR and Solarium.

Apache's SOLR is an enterprise-level search platform based on Apache Lucene. It provides a powerful full-text search along with advanced features such as faceted search, result highlighting and geospatial search. [...] If you're using PHP then the Solarium Project makes integration even easier, providing a level of abstraction over the underlying requests which enables you to use SOLR as if it were a native implementation running within your application. In this series, I'm going to introduce both SOLR and Solarium side-by-side.

He starts with some of the basic concepts behind what SOLR is, what kinds of things it's useful for and how to get it installed on your system (using Homebrew). He shows how to set up a sample schema including a detailed look at the different types and required fields it will need. As this is just the first part of the series, it stops there and will get into the actual PHP code for the interface in the next edition.

0 comments voice your opinion now!
solr solarium search engine tutorial interface opensource library

Link: http://www.sitepoint.com/using-solarium-solr-search-setup/

Suresh Ariya:
Implement Flash Messages using Session in PHP (Part 1 & 2)
February 06, 2014 @ 11:08:55

In a two part series on his site Suresh Ariya shows you how to implement "flash messages" in your applications (in a framework-agnostic way) with the help of a custom script and the current user's session.

As part of the post series, today we are going to see how we can implement Flash Messages using PHP Session. Before proceeding into that, first i like to explain what is Flash Message and its usage. [...] Flash message is a message that will be shown/displayed only once. if you reload the browser or navigated to other pages and came back, you won't see the same message displayed again.

In part one he introduces the concepts behind flash messaging and gets into the initial steps of the implementation via a "FlashMessageInterface" to define the structure. In part two he gets into the actual implementation and shares a script that uses a custom prefix to define the messages and the expected getter/setter methods as well as "clear" functionality.

0 comments voice your opinion now!
flash message series part1 part2 implementation interface

Link: http://sureshdotariya.blogspot.in/2013/12/implement-flash-messages-using-session.html

NetTuts.com:
SOLID Part 3 - Liskov Substitution & Interface Segregation Principles
January 27, 2014 @ 11:51:30

On NetTuts.com today they've continued their series covering the SOLID development principles with the next letter in the acronym - "L". It stands for the Liskov Substitution & Interface Segregation Principles. The tutorial also talks some about the "Interface Segregation Principle" as they go hand-in-hand.

The concept of this principle was introduced by Barbara Liskov in a 1987 conference keynote and later published in a paper together with Jannette Wing in 1994. Their original definition is as follows: "Let q(x) be a property provable about objects x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T." [or more simply] "Subtypes must be substitutable for their base types."

They include some example PHP code showing a base "Vehicle" class and first an example of doing it correctly (with the Template design pattern) and an example of an incorrect method, complete with tests. They then get into the Interface Segregation Principle, an interface that can be depended on to use the module, with the same car-related examples.

0 comments voice your opinion now!
solid design principles liskov substitution interface segregation

Link: http://net.tutsplus.com/tutorials/php/solid-part-3-liskov-substitution-interface-segregation-principles/

SitePoint PHP Blog:
Fun with Array Interfaces
December 09, 2013 @ 10:53:06

On the SitePoint PHP Blog a tutorial has been posted recently about having some fun with array interfaces via some of the functionality provided through the SPL (Standard PHP Library).

As a programmer who works with different languages every day, I find a lot of joy in learning how things are done differently in other languages and seeing if I can do the same in PHP. One thing I liked in particular in Python was how one can emulate features of native data types in custom classes. [...] I thought it would be nice if you could do the same in PHP on an instance of your custom classes and not only arrays. PHP lets us do this with array interfaces.

He illustrates his intent with some basic Python functionality and shows how to use various PHP interfaces to achieve a similar functionality. He talks about SPL interfaces like Countable, ArrayAccess and Iterator to make objects more useful in an array handling environment. His example uses the idea of a set of user's tweets (from Twitter) and shows the implementation of these three interfaces.

0 comments voice your opinion now!
array interface countable arrayaccess iterator tutorial

Link: http://www.sitepoint.com/fun-array-interfaces

Russell Walker:
Active Record vs Data Mapper for Persistence
October 18, 2013 @ 10:19:13

Russell Walker has a new post today comparing two popular methods for abstracting out database access and working with your data - the Active Record and Data Mapper patterns for data persistence.

These two design patterns are explained in Martin Fowler's book 'Patterns of Enterprise Application Architecture', and represent ways of handling data persistence in object oriented programming.

He gives simple code examples of both - one showing a basic "save" call with Active Record and the other showing the saving of a "Foo" entity using similar logic. Along with these examples, he also includes a few points about the major advantages and disadvantages related to the pattern. He also talks some about "service objects", the go-between that the data mapper pattern uses to combine business logic and the mapper object. He ends the post by making some suggestions about which to use, depending on the need of course.

0 comments voice your opinion now!
activerecord datamapper persistence database interface designpattern

Link: http://russellscottwalker.blogspot.co.uk/2013/10/active-record-vs-data-mapper.html

Procurios Tech Blog:
Autocompleting a lot of parameters
October 16, 2013 @ 11:14:05

Pim Elshoff has a recent post on the Procurios tech blog looking at autocompletion on function calls and an alternative to the "too many parameters" problem.

Some methods have many parameters. Sometimes they start out like that, sometimes they grow like that over time. Even though a maximum of two parameters is preferable, configuration for a method that does a big thing is difficult. Take curl for example; curl has a lot of options and so several wrappers around curl have arisen to deal with configuring it in a more humane manner. How can we keep the clutter of many parameters as low as possible, while maintaining autocompletion?

He gives an example of a function that takes too many arguments and how it's difficult to read (and remember the right order/types to give). He does mention one way that's sometimes used - arrays - but you lose typing checks with that. His best recommendation is to use a fluent interface instead. Not only does it make it more readable but it also works with the autocompletion in most IDEs.

0 comments voice your opinion now!
autocomplete parameters suggestion array fluent interface

Link: http://tech.procurios.nl/archief/2013/10/11/Autocompleting-a-lot-of-parameters

Stoyan Stefanov:
Server-side React with PHP
September 16, 2013 @ 09:28:24

On phpied.com Stoyan Stefanov has a new post showing how to do server-side React in PHP. React is a user interface library developed by Facebook and Instagram to make building UIs simpler.

So you know about React and how to build your own components. And you know you can run JavaScript inside PHP scripts, thanks to v8js. So nothing can stop you from rendering React components on the server side in PHP. Which means you send the first view from the server and then continue from there.

He walks you through the process step-by-step, showing how to set up the environment for the components and make a test file you'll use to build the components. He includes the Javascript code to make a simple table based on given data. Using the V8J libraries, he makes an object, pushes the Javascript string into it and render it to a string by executing the code. A screenshot is included showing what the output should look like.

0 comments voice your opinion now!
react ui javascript tutorial interface inside

Link: http://www.phpied.com/server-side-react-with-php

Reddit.com:
PSR-6 Caching Interface and PSR-5 PHPDoc enter Draft status
August 28, 2013 @ 15:30:29

As is mentioned in this Reddit post, two new PSRs have officially entered "Draft" status - PSR-5 for PHPDocumentor standards and PSR-6 related to caching implementations.

PSR-4 got to draft status a week ago and the other day it went into Review status. I pushed it to Review quickly as its already been around for several months (before this new workflow existed) so there didn't seem like much point in waiting. In less than two weeks we can put that in for an acceptance vote and we will have a new autoloader! Excellent. More good news from the FIG is that PSR-5 and PSR-6 are officially coming onto the scene, both now in Draft status too!

PSR-5, the PHPDoc standard, is more of an inclusion (and update) of most of the current standards people use when writing their PHPDoc comments, just more formalized by the PHP-FIG. PSR-6 is newer and is more akin to the logging PSR, defining the basic interface for an interchangeable caching layer. You can read more about each of the proposals in the mailing list: PSR-5: PHPDoc and PSR-6: caching.

0 comments voice your opinion now!
phpfig psr5 psr6 caching phpdocumentor phpdoc standard interface

Link: http://www.reddit.com/r/PHP/comments/1la27y/psr5_caching_interface_and_psr6_phpdoc_enter/

Project:
PHP DebugBar - In-browser Profiling Data for PHP Applications
August 13, 2013 @ 12:32:44

There's a handy feature in the Symfony framework that provides a "debug bar" with information about the execution of your application. But what if you don't use Symfony for your development? Enter PHP DebugBar. This handy tool is easily installable via Composer and has lots of useful features including:

  • Output of messages to the (Javascript-based) console
  • Viewing exceptions
  • Profiling database requests
  • Showing an execution timeline
  • Outputting the contents of the "request" (like superglobals)

It does all this completely independent of any other tool, so it's ready to drop into your application and go. You can find out more about the tool on the main project site or, if you'd like to contribute, you can find the project on Github.

0 comments voice your opinion now!
debug browser interface project tool

Link: http://phpdebugbar.com


Community Events





Don't see your event here?
Let us know!


podcast interview release community language threedevsandamaybe framework code configure library install wordpress unittest series list developer symfony application api introduction

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework