Avoiding Notices: When to Use isset() and empty()
One of the most confusing things for new programmers (and it even trips me up sometimes) is how to test for boolean conditions in code. As developers, we want to develop code that never emits notices or warnings, and PHP gets a bit antsy when we develop code that utilizes uninitialized variables. Lucky for us, PHP makes it easy to test for these variables without getting these notices.
PHP (like most languages) evaluates a logical argument left to right. For an AND condition, both conditions have to be true; PHP stops evaluating if it finds any condition untrue; that means that we can use isset() or empty() as the first parameter in an if statement, and avoid raising notices.
Configuring PHP: Essential INI Settings
When setting up a web server with PHP, there are a number of settings that are critical to consider. PHP 5.3 contains both a development INI file and a production INI file; however, users of older PHP releases (or those who don’t have direct control over their INI files) will want to pay attention and make sure that certain settings are configured.
These settings are the settings that I use whenever I configure a PHP server.
Accessing Databases with PDO: A Primer
With the introduction of PHP 5, the PHP Data Object was introduced as core functionality. PHP 5.1 turned on a minimum level of support for SQLite, by default, and PDO supports most of the major database engines. PDO offers a number of enhancements and improvements over the various database libraries (e.g. mysql_*, mysqli_*, pg_*), the biggest one being consistency. Still, the high level of code that involves direct use of the various database libraries means that PDO still isn’t as widely accepted as it should be.
This primer will show the various uses of PDO, and outline some of the benefits.
To The New PHP Programmers…
Nearly five years ago I started writing PHP code for fun. I had a project that I was working on, and I needed some sort of a programming language that would do calculations for me, and hopefully make managing a website easier. So I wrote my first web application.
Boy, was it bad.
How To Write A Function In PHP
PHP allows developers to write a variety of different styles of code: procedural, object-oriented, or simply scripts. This flexibility makes PHP easy to learn, and also means that new developers to PHP may not be programmers in other languages.
(more…)
Five Cool PHP Array Functions
Time and time again, I come across code that contains a variety of array-handling functions that too often duplicate the work that the PHP core team has done to develop built-in array functions. Since the built-in functions are inherently faster, trying to reimplement them in PHP will inevitably be a performance problem.
Here are five of my favorite array functions, along with their signatures and what they do.
(more…)
Object oriented programming always leaves you with a headache. What if you could master it instead? Stop struggling with object oriented PHP. Mastering Object Oriented PHP is the answer!
Imagine if you could write clear, compelling code each and every time you sat down to work. You can do this. I'll show you how with The Ten Commandments of Clean Code.
Brandon Savage has been a software developer since 2003. Ever since discovering that he could use software to automate routine tasks, he's been hooked. Brandon is passionate about perfecting the art of software development.