Tag: Zend

Quality Assurance in PHP projects

Hello my dearest Unit tester,

My profession is assuring quality in IT projects. For this I implement systems at my client their work environments so that development teams can deliver the best code possible. I also give workshops and recently I gave one at PHPBenelux on Quality Assurance in PHP Projects. It was a 4 hour workshop and got very good feedback.
The slides are here: http://www.slideshare.net/NickBelhomme/php-quality-assurance-workshop-phpbenelux

One of the feedback I got was also related to the PHPUnit training course excerpt I released some time ago to the community.
The reason why I did this is because I felt Quality in software projects can and should be assured. Quality assurance (QA) is not only lacking in most PHP projects but often – most of the time – projects in other languages such as Java or .Net also lack them. Operating systems, application, games and sites are often released followed immediately with a continuous stream of bug fix patches. This means quality assurance is not a language specific problem, but a project problem. Because independent from the language you are using , as soon as you do not have a quality assurance system in place you will sooner or later face a problem. After receiving a lot of requests asking for the demo project from the excerpt I have decided to put it on-line on Github.

It is on-line under a creative common license, meaning you can contribute freely to the project.
The only thing you need to do is create a Github account, fork the project, implement your improvements and or feature requests and then do a pull request.

The project is dependent on PHP 5.3 or higher and uses namespaces, SPL Exceptions, Closures. In short the works for you to play with all these latest programming technique introduced to the PHP community 2 years ago with the launch of PHP 5.3

A big thanks to Zend for hosting the project at http://nickbelhomme.projectx.zend.com.
They make certain all the necessary tools are available and updated to the latest versions.
This way you can see the project in action. It is a text-adventure game which accepts only text input.
Generally you will need to use commands such as “look”, “take”, “open”, “go to”, “use” and many others to advance in the game.

Have fun,
Nick Belhomme

Zend Framework Bug Hunting Day

Hello World,

I know it has been a while, no excuses.

But I have something important to tell the PHP community. Upcoming Saturday 08 November 2008 it is Bug hunting day. This BHD is  organized by phpBelgium and phpGG,  and sponsored by Zend, iBuildings and ServerGrove. If you would like to learn more about Zend Framework this is the day to do it. As this is the framework that will be worked on that day.

This makes it a great opportunity for beginners and experts in the field to sharpen their skills. Everybody has used a program that had bugs and those were very annoying. You hoped those would be fixed in the next release. Well we are going to open up Zend Framework and look at all the bugs that were committed to Zend and try to solve them. This means digging into the code and learning how everything works from the inside out. What a great opportunity!! We always need pratical uses to make studying pleasant and this is surely one of them. So take out your agenda and reserve this Saturday for a trip to Hotel de Goderie at Roosendaal between 11:00h and 17:00h. You would not only work on your favorite framework but also help the community.

It is free so please confirm your participation at Upcoming or at the website of phpBelgium or phpGG.

What to bring:

  • Good Humor
  • Motivation
  • A laptop
  • Money or a prepared lunch as this is not included in the day for people who have not registered. It has been provided by the Sponsors.
  • Another PHP Enthusiast

I will be joining this day, so I hope to see you then.

Happy Bughunting from Sunny Belgium,

Nick Belhomme
ServerGrove Webhosting    Zend The PHP Company     iBuildings The PHP Professionals

Zend PHP 5 Certification – Self Test

Today and from now on, on a regular basis, I am going to write about the ZCE Test.
http://www.zend.com/store/education/certification/self-test.php

I blog about it, because Zend has this great test online but doesn’t provide the answers. I know some of you will benefit greatly by me telling you the whys on every answer. But you should always take the test first!

Question 1
How can precisely one byte be read from a file, pointed by $fp?

A) fseek($fp, 1)
B) fgets($fp, 1)
C) fgetss($fp, 1)
D) fgetc($fp)
E) All of the above

The correct answer is fgetc($fp).
fgetcGets character from file pointer

But this definition on php.net is faulty. Beware fgetc() returns per byte as in the exam.  So if you use this function on a utf-8 formated file, you may encounter problems trying to display the character. As the ô character in the code below is split up over several lines.

Try the following code:

<?php
header('Content-Type: text/html; charset=utf-8');
$fp = fopen('somefile.txt', 'r');
if (!$fp) {
echo 'Could not open file somefile.txt';
}
while (false !== ($char = fgetc($fp))) {
echo "$char\n";
}
?>

and create in the same directory the following file: somefile.txt with the following content: “Bientôt!”

This will result in character encoding problems. Please do not forget to save your files in the utf-8 format. You have this ability in all good editors. If your editor does not support this, throw it away, set it on fire and forget about it. Check out Eclipse Zend, Zend IDE , phpED,  Komodo, …

Question 2
What object method specifies post-deserialization behavior for an object?

A) __sleep()
B) __wakeup()
C) __set_state()
D) __get()
E) __autoload()

The correct answer is __wakeup().

 The magic functions __sleep and __wakeup

__sleep
The standard PHP function serialize() checks if your class has a function with the magic name __sleep. If so, that function is being run prior to any serialization. It can clean up the object and is supposed to return an array with the names of all variables of that object that should be serialized. If the method doesn’t return anything then NULL is serialized and E_NOTICE is issued.

The intended use of __sleep is to commit pending data or perform similar cleanup tasks. Also, the function is useful if you have very large objects which need not be saved completely.

__wakeup
Conversely, unserialize() checks for the presence of a function with the magic name __wakeup. If present, this function can reconstruct any resources that object may have.

The intended use of __wakeup is to reestablish any database connections that may have been lost during serialization and perform other reinitialization tasks.

Question 3
Where does the session extension store the session data by default?

A) SQLite Database
B) MySQL Database
C) Shared Memory
D) File System
E) Session Server

The correct answer is the File system. PHP saves session data at the end of every request by default in a file in the system’s temporary directory. This is a great solution as it will serve for most websites. But as websites tend to grow and receive more traffic. With more traffic your server gets slow and at a certain point you will want to add more servers, so the work load can be divided between them. At this point you might consider storing session data in a database. Luckily PHP offers a solution to overide the default. session_set_save_handler().If you want more information regarding this issue check out devshed.

Question 4
Which of the following data types cannot be directly manipulated by the client?

A) Cookie Data
B) Session Data
C) Remote IP Address
D) User Agent

The correct answer is Session Data. Everything else can easily be forged. As this information is all stored client side. And Session data is stored server side by your PHP script.

Question 5
What is the difference between isset() and other is_*() functions (is_alpha(), is_number(), etc.)?

A) isset() is a function call and is_*() are not function calls
B) is_*() are language constructs and isset() is not a language construct
C) isset() is a language construct and is_*() are not language constructs
D) is_*() return a value whereas isset() does not

Isset() is a language construct. These are built-into the language and, therefore, they behaves differently than functions. They have their own special rules. Check out the following code.

<?php
/* Variable functions, PHP supports the concept of variable functions. */
$fruit = array('banaan', 'apple');
$variableFunction = 'is_array';
var_dump($variableFunction($fruit));

/* But Variable functions won't work with language constructs such as echo(), print(), unset(), isset(), empty(), include(), require() and the like.*/
$variableFunction = 'isset';
var_dump($variableFunction($result));
?>

This code will result in a fatal error.

Question 6
What will be the value of $b after running the following code?

<?php
$a = array(‘c’, ‘b’, ‘a’);
$b = (array) $a;

A) TRUE
B) array(‘c’, ‘b’, ‘a’)
C) array(array(‘c’, ‘b’, ‘a’))
D) None of the above

The correct answer is array(‘c’,’b’,’a’) as (array) is a type conversion operator also known as a cast operator.

The casting operators allow you to cast variables to new types. Unlike the settype function, they return a value that is the value of the variable cast in the new type.
It is used simply as the data type you want to convert to enclosed in brackets and placed before an expression.

The casting operators are:

  • (int) or (integer) to cast to an integer
  • (float) or (real) to cast to a floating-point number
  • (string) to cast to a string
  • (bool) or (boolean) to cast to a boolean
  • (array) to cast to an array, in this case it is already an array, so no changes are being made to the array
  • (object) to cast to an object

Question 7
Which of the following function signatures is correct if you want to have classes automatically loaded?

A) function autoload($class_name)
B) function __autoload($class_name, $file)
C) function __autoload($class_name)
D) function _autoload($class_name)
E) function autoload($class_name, $file)

The correct answer is __autoload($class_name).

Question 8
What is the best way to run PHP 4 and PHP 5 side-by-side on the same Apache server?

A) Run one as an Apache module, the other as a CGI binary.
B) Run both as a CGI binary.
C) Just use .php4 for PHP 4, and .php for PHP 5.
D) Use .php for both but use different document roots.

You should run one as an Apache module, the other as a CGI binary.

Of course PHP as a CGI is not quite the same as an Apache module, performance / $_SERVER variable-wise.  You’ll get better performance with PHP setup as a module. Not only will you not have to deal with the CGI performance hit,  but if some of your scripts use basic http authentication, they do not work if you run PHP as a CGI. Naturaly there are ways around this, but that is what Google is for.

I hope you learned some stuff, and I’ll see you at the next Zend Certified Engineer 8 questions test.

Sunny greetings from Belgium
Nick Belhomme

Ps. Do not forget to bookmark: http://www.zend.com/store/education/certification/self-test.php and take the test as it will keep you sharp or prepare you to take the real ZCE  exam!

It’s all about building the dream

Hello, thank you for reading up on my daily notes.

The other day one of my colleagues at Skynet Belgacom (Belgium’s reference provider of integrated telecommunication services) asked me if it would be difficult for him to obtain the PHP5 Zend Certified Engineer Certification.

Being a ZCE myself I was in the excellent position to answer that question for him.

I responded it wouldn’t if he really wanted it. It is the same as everything in life. People can do extraordinary things if they really, really want it. Do you ever stop and think when you see an airplane glide through the air that it was once just a man’s idea?! Man couldn’t fly, if he was meant to fly he would have gotten wings they told Wilbur Wright. Well we all know the Wright brothers showed us. Millions of people fly now a day, every day!

They made the impossible possible with their passion!

I hear people too often say what they don’t want, that they never even consider what they do want. If you want something and just take action you can grab it. Almost every time, guaranteed. Besides it is not the goal that makes it a success it is trying to reach that “want” that makes the trip and the total a success. You’ll never hear someone say when they come to pass, I had a great house, great furniture, a runway model as a spouse and 50 million on my bank account. No they will tell you all the great stories on how they achieved that goal. You see, it is not the achieved end that is a success it is the road trip and all the personal development you gained while taking the trip. Everything can be stripped and taken away from you, but not the development you gained. That’s yours for ever!

I told my colleague he should go for it. Posing the question if it is a hard thing to do indicated he wants the certification but is in doubt of himself or the work that is involved. I told him he shouldn’t be afraid of himself or of the work involved. Just go.

If you are interested in obtaining this certification yourself let me share a secret with you:

You can achieve this, I am positive you can!

I know you can, maybe you’ll just have to take the test and pass, maybe you will have to study for a month or even 2 years. But like I said before, if you want it, you can do it. Only the things that you have earned through hard work are the things that you really value. And what is wrong with hard work? Working towards the goal should be fun. And it will be if you are pursuing something you want. So take your time but start moving.

PHP Architect has this great mock exam . I suggest you take it to verify your readiness for the new Zend PHP 5 Certification Exam. It is just a test so if you fail don’t let it get you down, but see it as an opportunity for you becoming an even better programmer as it will indicate in detail which areas of PHP you have to sharpen. A great book called “Php|architect’s Zend PHP 5 Certification Study Guide” can help you with that.

If you are like me and pass with the grade “excellent”, get your butt to the nearest examination center and take that exam.

The benefits are huge, as an employee you can ask for a raise, you have a proven knowledge, and have something to brag about to your colleagues. 😉

As a freelance PHP Expert Developer Consultant like myself the benefits are even greater. Really big companies, as the one where I am doing a project right now, will contact you themselves. You have after all proven to have a very high know-how and experience in PHP.

But what we both share, employee and freelancer, is the deep satisfaction of knowing you wanted something, went for it, and obtained it. And this feeling is far more important than anything else. It makes you see. It makes you feel. And finally it makes you believe in yourself and know that when YOU want something, you can make it happen. Every time!

Sunny greetings from Belgium,
Nick Belhomme

Ps. I have a great house, great furniture, a runway model as a spouse and I am working towards the 50 million on my bank account. 😉

Some great books to help you prepare for the exam.

Zend Certification Study Guide Zend Practice Exam Book