Saturday, November 28, 2015

Is it always necessary to use "is_array()" before a foreach?

Many times I see a code, that fails because of one simple and very common programmer mistake.
Programmers often use variabled in foreach() construction without validation before.

This mistake may leads to unstable work of your code.
It must be a "golden" rule of every PHP programmer to always use a validation of  variable before running foreach() construction.

You may do it in few ways:

1. Direct validation:
if(is_array($users))   {
    foreach($users as $user){

    }
} 


2. Casting (not recommended, you know why, right?):
foreach((array)$users as $user){

} 

such way is better, but still...:
$users = (array)$users;
foreach($users as $user){

} 


3. Your own function for handling such cases:
function actionHandelingUsers($users)
{
    if(!is_array($users))
    {
        throw new Exception('$users must be an array');
    }

    foreach($users as $user){
        ...
    }
}

Ok, but sometimes I hear a following argument: my function is always returns an array, why do I need to perform a validation?

The answer is simple: there is no always in programming - what if I decide to change yuor function output? What will be with yuor code after the function will return TRUE instead of array()? You know, right - your code will crash...

The same answer about  using of empty() instead of is_array(): empty() doesn't check if the value is array... , so you may not use it in this case.

Wednesday, November 25, 2015

New version 4.3.9 of ApPHP Hotel Site script has been released

The new version 4.3.9 of ApPHP Hotel Site script has been released is available now for
downloading. There are some bugs fixed and many new additions and improvements, including new paid template.

ApPHP Hotel Site is a powerful hotel management and online booking/reservation site script. This script is the fully functional PHP solution to manage small to medium size of hotels, holiday flats or guesthouse. Our hotel reservation system allows you to start online reservation and customer management in minutes. It has been specially designed to simplify the task of hotel booking online.


Here the main additions and improvements in the last version:
Feature: [added] possibility to define separate payment gateways for hotels
Feature: [added] added MySQLi database driver
Feature: [added] possibility to allow using separate payment gateways for each hotel
Feature: [added] possibility to show checkin/checkout info on dashboard

Feature: [improved] css changes for rtl template for lytebox
Feature: [improved] structure of the core classes
Feature: [improved] removed option All Rooms from occupancy calendar for multiple hotels
Feature: [improved] installation wizard
Feature: [improved] syntax changes in PHP code and optimizations
Feature: [improved] security fixes in room prices and availability pages

Bugs fixed 
To view a Live Demo click here.

To download new version click here.