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

Mark Baker:
A Functional Guide to Cat Herding with PHP Generators
Jan 19, 2016 @ 10:05:13

In this post to his blog Mark Baker looks at a feature added in PHP 5.5 - generators - and how to use them with some of the array handling functionality PHP provides.

When working with arrays in PHP, three of the most useful functions available to us are array_map(), array_filter() and array_reduce().

[...] However, these functions only work with standard PHP arrays; so if we are using Generators as a data source instead of an array, then we can’t take advantage of the functionality that they provide. Fortunately, it’s very easy to emulate that functionality and apply it to Generators (and also to other Traversable objects like SPL Iterators), giving us access to all of the flexibility and power that mapping, filtering and reducing can offer.

He starts with a more "real world" example of using a generator in a handler for GPX files, XML files storing GPS data. He gives an example of the typical file contents and shows a simple generator script (class) that he uses to grab chunks of the file at a time instead of reading it all in and parsing it from there. He then uses this generator along with a bit of extra handling to mimic array filtering, transformation and reducing the data being returned.

tagged: functional generator tutorial array filter reduce transformation

Link: http://markbakeruk.net/2016/01/19/a-functional-guide-to-cat-herding-with-php-generators/

Mikko Koppanen's Blog:
Perspective transformations
Feb 05, 2009 @ 09:36:02

Mikko Koppanen is back to blogging with this new post today - it's a look at another example with ImageMagick. It shows how to distort an image but keep its perspective.

I took some time to actually understand the perspective transformations properly using the excellent ImageMagick examples (mainly created by Anthony Thyssen) as a reference. The basic idea of perspective distortion seems simple: to distort the control points to new locations.

His example uses a checkerboard as the image to manipulate and, based on an array of settings (source, destination) sets control points for the image to twist and turn from. The final output is echoed from a call to distortImage.

tagged: perspective transformation imagemagick twist bendexample

Link:

Christian Stocker's Blog:
Profile XSLT transformations within PHP
Apr 30, 2007 @ 10:09:00

Christian Stocker points out a handy patch for the PHP XSLT functionality today - one that allows you to test to see where in the transformation the most time is spent.

Look no further than this patch to the PHP XSL extension. It uses the built in profiler of libxslt to get the information which template was called how many times and how much time was spent in them. It may help in improving the speed of your XSLT transformations, like a PHP debugger can help in profiling your PHP scripts.

Besides the link, he also includes a simple sample script that uses the setProfiling function to write out to a text file the stats of the transformation. He also includes a (very beta) patch to the libxslt functionality itself to make it easier to not only time the overall execution of the xslt, but also allows for timing of other individual templates that might be included.

tagged: xslt transformation benchmark setprofiling patch download xslt transformation benchmark setprofiling patch download

Link:

Christian Stocker's Blog:
Profile XSLT transformations within PHP
Apr 30, 2007 @ 10:09:00

Christian Stocker points out a handy patch for the PHP XSLT functionality today - one that allows you to test to see where in the transformation the most time is spent.

Look no further than this patch to the PHP XSL extension. It uses the built in profiler of libxslt to get the information which template was called how many times and how much time was spent in them. It may help in improving the speed of your XSLT transformations, like a PHP debugger can help in profiling your PHP scripts.

Besides the link, he also includes a simple sample script that uses the setProfiling function to write out to a text file the stats of the transformation. He also includes a (very beta) patch to the libxslt functionality itself to make it easier to not only time the overall execution of the xslt, but also allows for timing of other individual templates that might be included.

tagged: xslt transformation benchmark setprofiling patch download xslt transformation benchmark setprofiling patch download

Link:

Dikini.net:
Rewriting macros - the peculiar case of php
Aug 17, 2006 @ 07:29:04

On Dikiki.net today, there's a new post that's a continuation of a series (first post, second post) dealing with macro programming in PHP.

Without going into theoretical details, some of which are quite alien to me, I'll try to describe some of the challenges that pattern patching rewriting macros might pose for a language like php. After brief explanation what kind of a beast is this, I try to explore some of the finer points, which might cause problems. The intent of this post is to sketch a design and highlight some of the possible issues.

He breaks up the post into a few sections:

  • pattern matching rewrite only macros - a bird eye view
  • Transformation time
  • Basic/skeleton shapes and intermediate shapes
  • Code generation issues specific to php
  • Hygiene
  • A rough macro shape outline
  • Output/Status of the project
There are code examples (of how it should work) and explainations of the issues PHP would face to accomplish this goal.

tagged: rewrite macro pattern match transformation skeleton generation hygiene rewrite macro pattern match transformation skeleton generation hygiene

Link:

Dikini.net:
Rewriting macros - the peculiar case of php
Aug 17, 2006 @ 07:29:04

On Dikiki.net today, there's a new post that's a continuation of a series (first post, second post) dealing with macro programming in PHP.

Without going into theoretical details, some of which are quite alien to me, I'll try to describe some of the challenges that pattern patching rewriting macros might pose for a language like php. After brief explanation what kind of a beast is this, I try to explore some of the finer points, which might cause problems. The intent of this post is to sketch a design and highlight some of the possible issues.

He breaks up the post into a few sections:

  • pattern matching rewrite only macros - a bird eye view
  • Transformation time
  • Basic/skeleton shapes and intermediate shapes
  • Code generation issues specific to php
  • Hygiene
  • A rough macro shape outline
  • Output/Status of the project
There are code examples (of how it should work) and explainations of the issues PHP would face to accomplish this goal.

tagged: rewrite macro pattern match transformation skeleton generation hygiene rewrite macro pattern match transformation skeleton generation hygiene

Link: