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

Lorna Mitchell:
PHP 5.6 and the Splat Operator
March 17, 2014 @ 09:05:36

Lorna Mitchell has a new post to her site looking at a feature of the upcoming PHP 5.6 release, the splat operator (three ellipsis...).

We have a couple of new features coming in to PHP 5.6 with names that sound much less exciting than the features they actually represent: "variadic functions" sound positively academic, and "argument unpacking" isn't exactly catchy. However they both use a new operator in PHP which looks like an elipsis (three dots ...) and is referred to as either the splat operator or the scatter operator. I included them in a recent version of my "Upgrading PHP" talk so I thought I'd share the examples here too in case anyone is interested.

She includes an example of it being used in a variadic function, one that lets you define an optional number of parameters without having to resort to func_get_args. She also talks about "argument unpacking" or the passing in of an array of values with the splat to have it handled like a string. An example with the mail function is included.

0 comments voice your opinion now!
php56 splat operator variadic function argument unpacking

Link: http://www.lornajane.net/posts/2014/php-5-6-and-the-splat-operator

PHPMaster.com:
Array Operators in PHP Interesting but Less Spoken
July 01, 2013 @ 10:56:43

On PHPMaster.com there's a new tutorial about array operators in PHP, more so how the usual operators interact with arrays.

Operators in PHP can be organized into seven different categories: arithmetic, assignment, bitwise, comparison, error control, execution, incrementing/decrementing, logical, string, array, and type operators. This article details working with array operators, but also covers how some of the other operators work when used with arrays.

They talk about the operators for:

  • array union (plus)
  • equality (double equals)
  • identity (triple equals)

They also talk briefly about some of the other PHP operators with arrays (like subtraction, multiplication and division) and some of the conversions that PHP does when they're used.

0 comments voice your opinion now!
array operator union equality identity other tutorial

Link: http://phpmaster.com/array-operators-in-php-interesting-but-less-spoken

PHPMaster.com:
Base Converting and Binary Operators
April 18, 2013 @ 11:44:05

On PHPMaster.com there's a new tutorial from Timothy Boronczyk focusing on the binary operators in PHP and using them to do some base conversions.

This article discusses PHP's binary operators and how to convert between different counting systems. Most programming books and articles only dedicate a page or two to such topics, and although using the operators is really quite simple, there's a fair amount of background knowledge one must have to use them correctly. Instead of giving the same bare-bones treatment that every other reference gives, I'll first provide you the necessary background in number theory. Armed with that knowledge, you'll be able to understand the binary counting system and base conversions… and familiarity with binary digits is the key to successful use of the binary operators!

As promised he starts off with some number theory complete with illustrations about base-10 and how the values fit into "buckets" of data. He compares this to base-2 (binary) and only then starts getting into the conversion functions. He shows the usage of things like decbin and dechex to modify the values as well as the use of bitwise and binary operators.

0 comments voice your opinion now!
converting binary bitwise operator tutorial numbertheory

Link: http://phpmaster.com/base-converting-and-binary-operators

Sherif Ramadan:
How to Write an Operator Precedence Parser in PHP
January 21, 2013 @ 11:21:22

Sherif Ramadan has a post looking at creating a better operator precedence parser in PHP. His example is a fully PHP implementation that takes equation strings and evaluates them to create the result.

Operator precedence parsers are very simple on the surface. So don't feel in the least bit intimidated, because by the time you've read through this I hope to have you walk away with a solid foundation on how to write your very own operator precedence parser. The goal is to understand how to solve the problem of operator precedence parsing, and not necessarily to write your own parser. Learning how the problem can be solved is the most important thing to take away from this article.

He starts with an introduction to the concepts behind "operator precedence" including processing order and grouping. He also mentions infix and postfix (RPN) notations for handling different formats of equations. He used the "Shunting-yard Algorithm" and how it relates to handling the different parts of the equation, one at a time, in the correct order. He rest of the post is dedicated to the details of the execution in the tool, including code examples and the tokenization of the strings passed into it.

0 comments voice your opinion now!
operator precedence parser string token shuntingyard algorithm


Reddit.com:
How and When do you use Bitwise?
April 06, 2012 @ 10:30:32

In this new question to Reddit, there's a question about the usage of bitwise operators - when they might come in useful.

As I get deeper into PHP I notice some lower level functionality that looks like it could be interesting, maybe even useful. I'm trying (other than switching the hex value of a color) to figure out when Bitwise operators might come in handy. Any real world examples?

Responses to the post mention a few cases they'd be useful in - handling permissions, route matching and error reporting. You can find out more about bitwise operators in PHP the PHP manual.

0 comments voice your opinion now!
bitwise usage opinion operator


Stoimen Popov's Blog:
PHP Performance Bitwise Division
January 06, 2012 @ 09:26:38

Stoimen Popov has a new post to his blog today comparing the performance of bitwise division versus the normal "/" division operator.

Recently I wrote about binary search and then I said that in some languages, like PHP, bitwise division by two is not faster than the typical "/" operator. However I decided to make some experiments and here are the results.

According to his results using the bitwise method is slightly faster, but you'd only really notice it when working with large sets of data (like his example using 10,000,000). The code to run his benchmarks is included in the post.

0 comments voice your opinion now!
bitwise division benchmark compare operator


Sameer Borate's Blog:
Disabling the silence @-operator in PHP
July 06, 2010 @ 08:42:22

As Sameer Borate points out in his latest post to his blog, there's a way to disable that pesky suppression operator (@) in your PHP installation thanks to the scream extension.

PHP supports one error control operator: the at sign (@). When prepended to an expression any error generated by that expression will be ignored. It can also be useful for hiding errors generated by various functions. [...] Although quite useful at some times, using the @-operator can have some annoying side effects.

He shows you how to install the extension on a stock Ubuntu platform (including the PHP packages) and how use the feature in your application by means of a call to ini_set (or, of course, setting it in your php.ini file).

0 comments voice your opinion now!
disable supress operator scream extension


Johannes Schluter's Blog:
Class posing and overloading the "new" operator
January 07, 2010 @ 10:24:16

In this recent post to his blog Johannes Schluter talks about a method he's suggested for testing objects in unit tests - overriding the "new" operator to replace specific classes with mocks.

Two years ago at some conference I had a conversation with Sebastian about the need for a way to overload the new operator in PHP so, probably, bad designed code can be tested more easily by replacing specific classes with mocks. [...] Sebastian then pushed the code as part of a new test_helpers extension with some documentation to github and I fixed some bugs in it. The aim of the extension is to collect functionality which might be beneficial for phpUnit and other test scenarios but which should never reach a production environment.

He includes some sample code to show it in action - defining the mock class, using the set_new_overload function to define it as what should be called when the "new" operator is used and a dump of the result.

1 comment voice your opinion now!
overload new operator mock unittest


ThinkPHP Blog:
Silence of the LAMPs
September 16, 2009 @ 09:13:40

In a recent post to the ThinkPHP blog Martin Brotzeller looks at a PHP operator that developers should just not use anymore - the suppression operator (@).

The silence operator exists to give programmers an easy way to suppress messages when a command might fail and the code checks for success itself (i.e. in those cases that raise errors instead of throwing exceptions).

He points out a popular use (like putting it on an fopen to prevent it from throwing an E_WARNING) but notes that this could cause trouble if the code is several layers deep and seems to fail silently. He gives en example of the Zend_Loader component of the Zend Framework and how, if the suppression operator was used, errors with an include failed without so much as a blip in the error log. While it seems handy, the suppression operator can cause more harm than good in the long run.

0 comments voice your opinion now!
suppression operator avoid


Mark van der Velden's Blog:
PHP Quiz part 2
May 14, 2009 @ 12:05:22

Mark van der Velden has posted another PHP quiz you can used to test your knowledge of the language:

A short quiz this time, but that doesn't make it less fun. Do you know the answer to all of them? Get a cup of coffee and kill 10 minutes with round two... As always, think of the answer before you execute the code or look it up. You can find round one here.

This one has questions on arrays, ArrayAccess, references, operator precedence and nesting structures. There's no answer key, so you'll just have to test it out if you want to see the answer.

0 comments voice your opinion now!
operator nesting reference array quiz



Community Events





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


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

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