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

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

NetTuts.com:
Reflection in PHP
April 19, 2013 @ 10:24:28

On NetTuts.com today there's a new tutorial talking about a part of PHP that can be quite powerful but isn't used too often - reflection in PHP. Using Reflection you can get information about your actual code and its elements without having to try to parse it yourself.

Reflection is generally defined as a program's ability to inspect itself and modify its logic at execution time. In less technical terms, reflection is asking an object to tell you about its properties and methods, and altering those members (even private ones). In this lesson, we'll dig into how this is accomplished, and when it might prove useful.

They provide a little context around the idea of "reflection" in programming languages and then jump right in with a few sample classes. They set up their "Nettuts", "Manager" and "Editor" classes and show how to use the ReflectionClass functionality to get their structure. The examples show how to get the class' methods, their properties and calling these methods using things like invoke and call_user_func.

0 comments voice your opinion now!
reflection tutorial introspection methods parameters invoke

Link: http://net.tutsplus.com/tutorials/php/reflection-in-php

Gonzalo Ayuso's Blog:
Performance analysis using bind parameters with PDO and PHP
October 06, 2010 @ 08:57:02

Gonzalo Ayuso has posted the results of some performance testing he did with bind parameters in a PDO-based request for his application.

Some months ago a work mate asked me for the differences between using bind variables versus executing the SQL statement directly as a string throughout a PDO connection. Basically the work-flow of almost all database drivers is the same: Prepare statement, execute and fetch results. [...] What's the best one? Both method work properly. The difference is how databases manage the operation internally.

He gives two code examples, one with the bind parameters and one without, and the benchmark code he used to generate his statistics. It uses a PDO connection to execute several statements in a row both with bind parameters and without, measuring the time (with microtime) and outputting the results. His results show that while the simple update is faster, the bind parameter method has the added benefit of reusability for multiple queries.

0 comments voice your opinion now!
performance bind parameters pdo analysis benchmark


Jani Hartikainen's Blog:
A simple way to make your code better Stop adding more parameters
November 12, 2009 @ 11:19:08

Jani Hartikainen offers a simple suggestion for making your code better - stop adding more parameters.

You need to add some new functionality to your function or class. Let's say you need to remove all objects stored, but optionally also call a method on them. It's pretty simple, isn't it? Let's just add a parameter to removeAllObjects! If you make it true, the additional method is called, otherwise not. Except it's not really such a good idea at all...

He points out that there's nothing wrong with parameters, it's their overuse that can cause the issues - if, in using them, it's unclear what they're doing, don't use them. He includes a few rules for making good use of parameters: less is good, relationship to the function, parameter order importance and using the language's parameter handling to your advantage.

0 comments voice your opinion now!
parameters opinion better code


Harry Roberts' Blog:
Flexible PHP Interfaces
June 11, 2008 @ 13:40:10

In an effort to breathe as much life into an old bit of software he was having to update, Harry Roberts worked up a list of things that he sees can make things a bit more "programmer friendly" when it comes to using classes, methods and interfaces in your code.

His list of four is:

  • Doc Comments
  • Flexible Parameters
  • Use method Entry contracts
  • Be Stateful and Refactor

The "Doc Comments" is pretty obvious, but some of the others need a bit more explaining. Being flexible with your parameters is more about requiring the least from a developer, "entry contracts" being the restrictions to let the developer know what you're expecting and refactoring commonly used functionality into a easy, single point of contact.

0 comments voice your opinion now!
flexible interface comments parameters entry contracts stateful refactor


The Shadow Fox Network:
Create Dynamic URLs With Mod_Rewrite and PHP Functions
October 26, 2006 @ 11:12:00

On the Shadow Fox Network, there's a new tutorial that shows how to combine the Apache mod_rewrite functionality with some PHP functions to make passing variables over your rewritten URL easy.

You can't pass variables well without adding more commands to mod_rewrite. So here you'll learn to add unlimited parameters to your links with only one simple PHP function.

He starts with a mini-refresher course on the contents of the previous article and moves to the simple rewrite example that makes it possible - a two line statement. Then, it's on to the PHP - again, a simple function that does things simply, grabs all of the parameters from the URL and splits them out into a global parameters array. He even includes a simple example as a tutorial you can try out with the demo.

0 comments voice your opinion now!
tutorial modrewrite apache passing parameters simple function tutorial modrewrite apache passing parameters simple function


SitePoint Site Marketing Blog:
Track Your Rank Using the Google API
April 12, 2006 @ 07:24:27

Sitepoint, widely known for quality in content and tutorials, has a new post on its Site Marketing blog today dealing with tracking a site's Google ranking with the help of the Google API and the PEAR SOAP package.

Bernard Peh, the author, sets up what the Google API is and includes the way to grab your own API key (your pass into the powerful Google backend). The other two requirements for the project are the PEAR SOAP package and an install of at least PHP 4 or higher.

There's a list of input parameters for the functionality, with each described for what it does, and pley of code to help you integrate them into the API call. They give the example of the class grabbing the needed info (via SOAP), parsing out your URL from those results, and a simple form to make checking different URLs all the simpler.

1 comment voice your opinion now!
google rank api key pear soap parameters google rank api key pear soap parameters



Community Events





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


opinion voicesoftheelephpant language update security podcast package release tool series interview laravel framework introduction community symfony composer version install library

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