Programming the new world

Programming your life and the net, one day at the time

Category

Zend PHP 5 Certification - Self Test

Posted in August 4th, 2008
Published in PHP

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!

Another Project Succesfully Completed

Posted in July 2nd, 2008
Published in PHP

Dear readers,

I am really enthused about the project that was completed today. After months of dedicated work the Belgacom Skynet team and its partners really delivered. During this time I have been working in a great team which consists of web developers, integrators, database engineers, managers, editors, functional analysts and testers. The spirit and the drive of this amazing team is through the roof. Like I said in one of my previous posts “Never work a day in your life again” work really doesn’t feel like a job when you love what you do. The project consists of 6 (SIX!!) complete new websites. No matter what age you are, no matter your interest, if you can read dutch or french it will get you hooked in one two three. Let us look at the websites one at the time.

Skynet News
News and Sport:

If you are interested in the daily news the content of this segment is immense. It ranges from the latest news in Belgium, the world, politics, entertainment, economics, sport to the latest results from the lottery.
You can read thousands of articles or view the videos in streaming format.

It also has a handy weather feature. If you want to know the weather conditions for the upcoming days just look it up at the click of a button.

Skynet Lili
Lili:

This site is especially for women. Ranging from pregnancy to showbiz gossip. Read up on wellness, gastronomy, feelings, kids, family,…


Skynet Jack
Jack:

The fast lane. Cars, stock and finance, babes, adventure, lifestyle, gadgets…

Skynet Entertainment
Entertainment:

Concerts, movies, music and so much more. The one stop for leisure time.
You can download the latest charts, view the latest trailers and read up on the blogs of other people interested in entertainment.


Skynet Services
Services
:

A couple of keywords:

  • Route planner
  • job seeker
  • car finder
  • buy and sell
  • dating
  • search
  • yellow and white pages



Skynet Mobile
Mobile:

All proximus customers will be pleased to read that all the services from live.proximus.be are integrated in this easy to navigate segment.



I hope you have fun surfing on the latest project I am involved in. I plan on doing a lot more projects in the future, but this will always be one of the sweetest. The next big thing should be the completion of my book: the lives of the very successful.

Sunny greetings from Belgium

Nick Belhomme
Always looking for ways to stretch my capacity.

The elephpants kick in

Posted in May 2nd, 2008
Published in PHP
Tags: ,

PHP is conquering the world by stampede.

elephpant
I created this flag under GPU General Public License, so take it!

Sunny greetings from Belgium

Nick Belhomme

Lives of the very successful

Posted in April 27th, 2008
Published in PHP, my life

Dear reader,

Today I am going to write about the ultimate risk-takers, the masters of the universe, the go-getters and the achievers. They are such inspiring role-models it is only natural for me writing a book about them. The book should be finished in August this year and a lot of important names have already agreed to cooperate with it. This will make the book on itself a success, but I promise you dear reader, that it will be so much more. It will be a book that opens your eyes with real life examples that you can indeed achieve your goals. Be it founding your own company, being a guru with several books written, having a top executive position in a multi-million dollar company, being a founder of the latest web 2.0 hype bought in for a part of it shares by Microsoft.

Everything is possible. And this book will show you how they did it. Inside the masters of the universe will show you how.

Interested in reading the book? Interested in an eye opener that will change your life for the best? I know you are! But you’ll just have to wait till August.

Want to be one of the first? Write me an email if you want to be notified when the initial draft is distributed.

And if you know someone in IT, for who work and career take on the quality of a mission, and have succeeded in making their goal a success, just email me their name, and perhaps he or she will be included in the book.

Sunny greetings from Belgium

Nick Belhomme