$x = NULL; if (‘0xFF’ == 255) { $x = (int)’0xFF’; } This problem tests your knowledge of how type juggling, or coercion works. When a string and a number are compared with the equality operator, the string is coerced
and, it’s not what you expected
$x = true and false; var_dump($x); This one is interesting. In PHP, you can use && or and to do a logical comparison. However, due to the Operator Precedence rules, and actually has lower precedence than =, where && has higher!
Testing your knowledge of array_merge
$arr = array(); $arr[‘val1’] = array(1, 2); $arr[‘val2’] = 3; $arr[‘val3’] = array(4, 5); $arr2 = array(); $arr2 = array_merge($arr2, $arr[‘val1’]); var_dump($arr2); $arr2 = array_merge($arr2, $arr[‘val2’]); var_dump($arr2); $arr2 = array_merge($arr2, $arr[‘val3′]); var_dump($arr2); There’s a problem with this code. It lies
Watch out for that Octal!
var_dump(0123 == 123); var_dump(‘0123’ == 123); var_dump(‘0123’ === 123); At first glance one might think that the leading zero on line one is simply of no value. But one would be wrong… In PHP, a leading zero in a number
strpos gotcha!
$string1 = ‘php is fun!’; $string2 = ‘php’; if (strpos($string1,$string2)) { echo “\”” . $string1 . “\” contains \”” . $string2 . “\””; } else { echo “\”” . $string1 . “\” does not contain \”” . $string2 . “\””;
Post-Fix Increment Problem with Solution
Today I saw an interesting problem. At first glance I wasn’t sure what I was looking at. It took me a moment to parse it. Here is my own version of the problem: $x = 3; echo $x; echo “<br
Making progress in Laravel
I’m making good progress in learning Laravel. I just wrote a service provider, and then created a Facade for it. The concepts are coming together nicely. Here are a few of the pages I used to help figure this out: https://laravel.com/docs/5.2/providers#registering-providers
Laracast: Laravel 5 Fundamentals
Today I’m starting the Laracast “Laravel 5 Fundamentals”. Let’s see how long it takes me to complete it…
Factories and base classes
Today I refactored some code, And for the first time ever I wrote a factory class. I have a class that calls a specific service on the web. I had that class directly referenced in other parts of my code.
PHP Architect’s Zend PHP Certification Study Guide
So, today I started chapter three, on arrays. I learned something new! The list() function. That may just come in handy someday. 🙂
The Checklist Manifesto
At SunshinePHP this year, at one of the talks, the speaker mentioned a book called “The Checklist Manifesto”. I started reading it yesterday and I’m halfway through it already. It’s a good read that explains why checklists are so vital
Sunshine PHP 2015
This year’s Sunshine PHP conference is only the second I’ve attended. My first was Tek in Chicago, in 2013. Having 2 years of PHP experience behind me now has made a big difference in my understanding of the topics presented
Which way is better?
While going though some code in a plugin (not one I wrote), I came across the following snippet: if ( !isset($update_transient->checked) ) return $update_transient; else $themes = $update_transient->checked; Looking at this makes me cringe. Here’s how I would write this:
2014: A look back
So here we are on the eve of a new year. 2014 has been a good one for me. I decided to look back over my posts for the year, and discovered that I only posted 10 times in 2014!
WordPress plugin OOP template
<?php /* Plugin Name: Plugin URI: http:// Description: Version: 1.0 Author: Kenny Ray Author URI: http:// License: GPL2 */ if (strpos($_SERVER[‘SERVER_ADDR’],’localhost’)) { error_reporting(E_ALL); ini_set(‘display_errors’, 1); } // Be sure to update this name, and make the one at the very
Installing Laravel site: permissions
If you get this error Error in exception handler. when trying to hit the root of a new install, do these two things on OSX: sudo chown -R _www app/storage (replace _www with your Apache server name if necessary)
SRP : Single Responsibility Principle
This is the clearest beginner level explanation of the Single Responsibility Principle that I’ve seen so far: http://code.tutsplus.com/tutorials/solid-part-1-the-single-responsibility-principle–net-36074
Learn Composer
I just found a really good video tutorial on Composer: http://knpuniversity.com/screencast/composer/composer
How to handle login correctly in an iPhone app that connects to a web service
I am currently designing an iPhone app. It uses a web api that I’m building in PHP. The app requires users to login. What I am currently researching, and having a really hard time figuring out, is if there is
PHP Sessions: Part 4
Session Locking. Some people don’t ever consider this. I have dealt with it before in another language, so I decided to do a quick search to see what it looks like in PHP. The basic idea is that only one