Testing Your PHP Code

October 22nd, 2014

simpletest-logoPHP programming is definitely not all about the coding. This is actually for programming in all kinds of languages. It is also true for any kind of PHP application you may be working on, be it a PHP-based software asset management tool, a PHP-based website, or any other software.

Of course, when programming knowing coding best practices is essential, but having an in-depth knowledge of testing tools is equally important. For PHP testing frameworks used fall under different kinds of testing such as unit testing, integration testing, functional testing, behavior-driven development tools, and generic frameworks.

Each testing tool is obviously suitable for difference scenarios although they all serve the same purpose of decreasing dependence on manual testing. This makes the testing phase go more efficiently and save a lot of resources not only in terms of time but also in manpower, with less testers needed.

As a PHP programmer, make sure you brush up on your knowledge about automated testing skills and you’ll be the one who will benefit from it in the end.

Image via SimpleTest

Extracting More from PHP with the QB Extenstion

October 15th, 2014

QB logoOne of the weaknesses of PHP is that it isn’t doesn’t perform to well when used to develop computationally intensive tasks. Sure, its great for even the most complex of web applications, but is often skipped over in preference of another language for when it comes to computing.

An extension for PHP called QB, remedies this problem “by translating Zend opcodes and executing them through a statically typed virtual machine” resulting in a significant gain in performance even for complex tasks such as pixel-level image manipulation.

If you are new to PHP though, barely understanding the array chunk function, dabbling with PHP+QB is not advised and would be akin to handing your platinum credit card over to a teenager for use; perfect recipe for a disaster. Advanced programmers could benefit from this though it is recommended that you have a pretty fast system once you start compiling since compiling QB from source code is quite memory extensive, requiring at least 2 gigabytes of memory.

Photo Credit

Embedding Comments

October 8th, 2014

Now, to make you a better programmer we all know the value of comments. This allows you to understand the code that you have written defining and given meaning to operations as you build them up. You start with the terminators used by PHP and end with them as well. Single line comments look like this �// comment� and Multi-line ones use the syntax /* comment comment*/. A better example would be the one below:

//comment
/* comment
Comment*/
?>

In the next post we take on the best parts of PHP which would be variables which is essential in all programming languages.

PHP Development Tools Released

October 1st, 2014

devtoolsThe PHP community has again gotten a boost with the announcement that Eclipse is set to release their much loved PHP Development tools later this month. The developer tools included in the release is set to again make the lives of PHP developers a whole lot easier and has been since they released the last version (1.0) in 2007. The new release features a new and improved dynamic language toolkit that gives PHP more bite compared to its older counterpart. It is also designed to work with Java so any developed projects can easily be imported into the dynamic language toolkit. Better code testing tools allows faster error checking making development faster and testing is a breeze with better functionality making PHP easier to use and deploy. With this, the PHP community is set to get a boost and life would be a little bit easier in the wild that is the internet where all is supposed to work.

More Programming Basics

September 24th, 2014

As with all programming languages PHP has different variable types such as numeric, character, string and Boolean types. Boolean variables in PHP always return either true or false, integers are whole numbers, floating points are decimal or scientifically notated and strings are a chain of characters. Sounds familiar, well they are and they are mostly standard across the various programming languages. For a more in-depth discussion on the different data types of PHP go visit the manual page.
We next discuss operators such as the assignment operator which allows you to assign values to variables allowing complex operations to be constructed into more and more functional programs.

Further shortening of your code (Part 1)

September 17th, 2014

Many people are using PHP for development and most have truly mastered the art of programming the easy way round. Sadly, many older web sites that used these older styles of programming are not only long but reminiscent of reading something similar to alien writing that is long and incomprehensible to the layman. But good for all of us, there are some people out there who are willing to share their learned ways to those who are just beginning to master the strengths and powers of PHP. The traditional PHP way of checking for Boolean expressions was long and filled with those double equal signs (==)and others that were akin to some other mathematically adept languages but there are simpler ways of doing things as there always is with any language. In the next post we would give and example of the concept.

Cookies – not the one you dunk in milk

September 10th, 2014

If you have been browsing the web foir quite sometime, then you might have come across cookies which allows your browser to remember passwords and other information that may have anything to do with your actions on a particular website. These can be preferences that would allow the browser or webpage on the browser to determine your habits online allowing it to perform the requested operations faster and easier. A cookie is called a client-based information for it is stored on the client computer (yours when you browse the web) and is taken or stored intact along with all the information it contains for a specified amount of time or till you delete your browsing history and cookies. If you have come across tracking cookies, these are information that defines you to a particular web page which is called upon on your next visit. When creating cookies with your page, there are specific parameters (cookies by the way are created using user-made code in PHP) that must be remembered so as not to fill up the hard disks of your client computers as they visit your website page again and again. The function setcookie is used with the following syntax:

setcookie(var1, var2, time)

The var 1 stands for the name of the cookie you are creating, with the var 2 containing the value of the said cookie and the last parameter is the time which specifies the amount of time it takes for the function to kill (terminate/delete) the cookie. A more defined and elaborate explanation of the function can be found on this <a href=”http://www.php.net/manual/en/function.setcookie.php”>page</aq>.

Array_diff_uassoc Function

September 3rd, 2014

Next in line is array_diff_uassoc() function which compares two or more arrays while checking for differences before comparing the keys with a user-defined location. It then returns an array withthe keys and values from the first array(to which all the values were comapred against) it the function allows it. Syntax is as follows : array_diff_uassoc(array1,array2,array3….,function). with a sample below of how it is used.

function userdefined($v1,$v2)
{
if ($v1 === $v2)
{
return 0;
}
if ($v1 > $v2)
{
return 1;
}
else
{
return -1;
}
}
$a1=array(0=>”Dog”,1=>”Cat”,2=>”Horse”)
$a2=array(3=>”Dog”,1=>”Cat”,5=>”Horse”)
print_r(array_diff_uassoc($a1,$a2,”userdefined”));
?>

which results in the following output : Array( [0] => Dog [2] => Horse). For an example of the same function with two or more assigned arrays to the function:

function userdefined($v1,$v2)
{
if ($v1 === $v2)
{
return 0;
}
if ($v1 > $v2)
{
return 1;
}
else
{
return -1;
}
}
$a1=array(0=>”Dog”,1=>”Cat”,2=>”Horse”)
$a2=array(3=>”Dog”,1=>”Cat”,5=>”Horse”)
$a3=array(6=>”Onyx”,0=>”Dog”,5=>”Horse”)
print_r(array_diff_uassoc($a1,$a2,$a3,”userdefined”));
?>

Which in turn, gives you : Array ([2] => Horse )

So we see the different array_diff function variants and the diffeerent ways they are used to compare the values of one or more arrays with one another.

Online computer programming courses

August 27th, 2014

There are varying reasons behind one’s choice of becoming a computer programmer. There are those that simply have the skills, others are just very eager to learn more about computers, while of course, those that want to earn big. These varying reasons led to the continuous demand for computer programmers which eventually made such career to be easily attained through convenient yet beneficial online computer programming courses. Why are these courses beneficial? Just like any traditional computer programming courses, these as well cater to essential learning and exposures that definitely develop one’s skills and experience. These courses as well pave way for effective yet convenient learning mainly because these are known for being flexible. Students are given the freedom to choose their own schedule and still cater to other priorities such as other work, studies, family, and even leisure. These courses are options that people with interest in computers should definitely consider.

Arrays

August 20th, 2014

Arrays are what tables are to C-based programming languages and what databases are for SQL-based languages. Arrays or tables as they are sometimes called can be used to store the contents of several variables and to create one, you use the following syntax:

Array(key=>value)

The array in the syntax refers to the name of the array being created, the key is the index which is set automatically to a numeric character or string if none is specified. Value is the assigned value or content of the said array which can be seen easily in the following array creation example:

$b=array('z'=>‘Comedy”,’y'=>”Horror”,’x;’=>”Action”);
print_r($b);
?>

This piece of code would produce an output of :

Array ([0] => Comedy [1] => Horror [2] => Action)

More on array functions in the next posts.