I just ran into an interesting question while studying for the Zend certification, and I thought I would share because I was very confused.
What is the output of the following:
<?php
$a = 010;
$b = 0xA;
$c = 2;
print $a + $b + $c;
?>
I just ran into an interesting question while studying for the Zend certification, and I thought I would share because I was very confused.
What is the output of the following:
<?php
$a = 010;
$b = 0xA;
$c = 2;
print $a + $b + $c;
?>
Over the next couple weeks I'm going to be writing a series on programming design patterns and their applications. I plan to cover the popular patterns as well as the lesser-known, yet still insanely useful, ones too. This first article will go over the background and basics of a design pattern - What they are, why you should care, and how to implement one into your application.
Often one of the first patterns that young developers encounter, the singleton solves a very sloppy, dangerous, and nightmarish practice known as global variables. There are components in nearly every application that need to be accessed everywhere. Configuration variables are a perfect example of this. The younger developers might be tempted to declare a debug variable as global, and just access it where he/she pleases. You will learn later on in the project that this makes maintaining the application very frustrating.
We have all gone back and looked at code we wrote in the past and thought "Wow, this is ugly.", or "wtf was I thinking?", or even "I wrote this yesterday, and I have no idea what it does." Refactoring is the process of going back over already-working code and cleaning it up for the sole purpose of understandability, maintainability, and preserving your self-worth if anyone else were to take a peak. No one likes to be humiliated by their own code.
I have fallen in love with CakePHP's integration of the SimpleTest
libraries. With the type of work that I normally do, unit-testing is
hard to utilize successfully. That is to say, most of the applications
I work on have very straight-forward components and not a lot of
complex functions/methods. I would only be testing whether or not they
worked at all, rather than if they worked in a wide-array of
situations.
For example, unit-testing a simple news list and detail page is
probably overkill. Sure, you can test your classes by simple
instantiating them but that only goes so far. My new method involves
using SimpleTest's Scriptable Browser to actually crawl webpages and
ensure that the proper data is being displayed. That way, I can catch
all my php errors, including notices and warnings, insure that the
proper headers are being sent, and assert that certain text is
appearing on the page. Unit-testing will rarely catch a poorly coded
method that throws a PHP notice whereas the Scriptable Browser will.
Automagically generated date/time input fields normally default to the current date and time. For a couple of reasons, I had to change this to another default value. For example's sake, let's say I needed a time field to always select 1:30 pm in an add action.
Run of the mill example:
<?php
echo $form->input('start_dt');
?>
This will output 3 select boxes; one for hours, minutes, and the merdian (am/pm) with the current time pre-selected. So if it was 3:04 pm, that would be selected.
So lets change this so that 1:30 pm is always pre-selected:
<?php
echo $form->input('start_dt', array('selected' => array('hour' => '1',
'minute' => '30',
'meridian' => 'pm')
)
);
?>
That's all there is to it! Cake's automagic owns. Hope this helps someone else :)