News Feed
Sections




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

Nikita Popov:
The case against the ifsetor function
January 13, 2014 @ 09:22:52

In his latest post Nikita Popov aims to make a case against the introduction of the "ifsetor" function to be introduced into the PHP language. This function takes in a variable to find and, if found returns it. If not, it doesn't produce an error (or warning).

Recently igorw wrote a blog post on how to traverse nested array structures with potentially non-existing keys without throwing notices. The current "idiomatic" way to do something like this, is to use isset() together with a ternary operator. [...] Someone on /r/PHP pointed out that there is an alternative approach to this problem, namely the use of an ifsetor function.

He goes on to talk about by-reference argument passing, why requesting an undefined array index doesn't really throw an error and how writes don't have the same issues as reads. He then gets into his own issues around the "ifsetor" function, namely:

  • Creation of dummy values
  • No notices for nested indices
  • Null values treated as non-existing
  • Default is always evaluated
  • By-reference passing often forces a copy

He summarizes most of the issues in one statement - "there is way too much by-ref magic involved". He then looks at some of the ways that this could be helped but opts instead for something more like "get_in" as proposed by Igor.

0 comments voice your opinion now!
ifsetor getin array read write problem byreference

Link: http://nikic.github.io/2014/01/10/The-case-against-the-ifsetor-function.html

blog comments powered by Disqus

Similar Posts

PHP-Coding-Practices.com: How I Turned A Slow Array Sort Into A Quick One Using Quicksort Algorithm

Chris Shiflett's Blog: Sorting Multi-Dimensional Arrays in PHP

Eran Galperin's Blog: Passing arrays to Zend_Controller_Router

Gonzalo Ayuso: The reason why singleton is a "problem" with PHPUnit

PHP.net: PHP 4.4.2 Released


Community Events





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


code install interview release testing configure refactor unittest community threedevsandamaybe developer series opinion list language laravel podcast framework introduction wordpress

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