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

Leve.rs:
Array Manipulation in PHP, the Correct Way
Nov 08, 2013 @ 16:08:04

On the Leve.rs blog there's a recent post showing what they consider is the right way to work with arrays in PHP. It shows three things you can do to use PHP's own functionality to more correctly perform some common array operations.

More often than not, when PHP developers debug others’ code, the majority of each method is taken up by array manipulations. Spending this much time on array manipulations is a huge hassle when trying to understand any given method. In order to speed up the debugging process, it’s important to start writing array manipulations the correct way, first. Here are a few examples of code I have either written myself or had to fix in the past. It is time every PHP developer knows how to manipulate arrays properly!

Their three tips relate to:

  • Merging Arrays
  • Array Value Manipulation (with array_walk)
  • Array Value Manipulation (append with the plus sign, "+")
tagged: array manipulation correct merge value walk plus

Link: http://leve.rs/blog/correct-array-manipulation-in-php/

Gareth Heyes:
Tweetable PHP-Non Alpha
Dec 13, 2012 @ 15:40:25

Gareth Heyes has a new post that shares some of his efforts to write "non-alpha PHP", using characters other than the alpha-numeric ones to write executable PHP scripts. In his case, this involves a lot of pluses, underscores and square brackets.

I started to try and break the 10 charset limit of PHP non-alpha after @InsertScript showed me that PHP Dev supports [] syntax for arrays. I wondered if it would be possible to break the limit within production PHP. At first I thought you could but then after some testing I found that there was no way to concat without “.” and no way to call a string as a function without $ and =. However since I got into PHP Non-alpha again I thought why not try and improve it and make the code tweetable.

He works through the whole process of his discovery - starting with the creation of a non-alpha version of "0" (zero), moving into letter creation and finally all the way up to a full word..."assert". The result is tweetable code that echoes that string and contains more symbols than letters. If you're interested in more of this non-alpha kind of coding, check out some of the other posts on his blog.

tagged: nonalpha code tweet plus underscore squarebracket

Link:

Ian Christian's Blog:
Should you learn a framework?
Aug 01, 2008 @ 17:57:12

With more and more frameworks popping up every day in the PHP community, it's important to ask yourself one question - should I learn a framework? Ian Christian tries to answer that question in a recent post to his blog.

With other programming languages designed for the web, there's typically a framework that works hand in hand. [...] I imagine people will always write from the ground up with PHP, some people do it to learn, some I suspect think there's nothing out there that can do what they want, where as others perhaps do it just to prove themselves, or to gain fame. Good luck to them all, some of them are probably going to do a good job, but alas - I imagine most are wasting their time.

He breaks his opinions out into two sides of the argument - the business issues and the developer side, each with their own plusses and minuses. Overall, though, he definitely suggests learning some kind of framework, even if you don't end up working with it - it's just good experience.

tagged: framework learn opinion business developer perspective plus minus

Link:

Dallas PHP Users Group:
PHP4 to PHP5 Minor gotcha
Jan 12, 2006 @ 12:58:21

On the Dallas PHP Users Group website today, there's quick little "gotcha" by MonkeyT when it comes to using the strtotime() function.

strtotime translates a date presented in various formats into a unix timestamp. It allows the syntax "+2 weeks" and various other time units to push that chosen date translation into the future. In 4.3.10, php would allow a space between the + and the beginning of the parameter. that doesn't seem to be the case any more. ("+3 days", not "+ 3 days"). Other than that, pretty smooth changeover so far.

It's pretty subtle, but I could potentially cause some headaches in the future - so keep an eye out!

tagged: php4 php5 upgrade strtotime space after plus php4 php5 upgrade strtotime space after plus

Link:

Dallas PHP Users Group:
PHP4 to PHP5 Minor gotcha
Jan 12, 2006 @ 12:58:21

On the Dallas PHP Users Group website today, there's quick little "gotcha" by MonkeyT when it comes to using the strtotime() function.

strtotime translates a date presented in various formats into a unix timestamp. It allows the syntax "+2 weeks" and various other time units to push that chosen date translation into the future. In 4.3.10, php would allow a space between the + and the beginning of the parameter. that doesn't seem to be the case any more. ("+3 days", not "+ 3 days"). Other than that, pretty smooth changeover so far.

It's pretty subtle, but I could potentially cause some headaches in the future - so keep an eye out!

tagged: php4 php5 upgrade strtotime space after plus php4 php5 upgrade strtotime space after plus

Link:


Trending Topics: