Archive for August, 2010

Introduction to PHP5

Hey readers,

U’ll be going through the features of PHP 5
Before going throught the new features added in PHP 5
lets brushup some basic topics abt PHP

what is PHP ?&
PHP is server side scripting language

What is server side scripting language.

PHP – Hypertext preprocessors.

Server side scripting language.:
A server side scripting languague is nothing but scripts are run directly on the webserver to generate dynamic web pages.
IT is usually used to provide interactive web sites that interface to databases or other data stores.
The primary advantage to server-side scripting is the ability to highly customize the response based on the user’s requirements, access rights, or queries into data stores.

Zend engine for the brain of PHP5. Before going into features of PHP5
We should know what is a ZEND ENGINE

What is a Zend engine?

The Zend Engine is the internal compiler and runtime engine used by PHP4. Developed by Zeev Suraski and Andi Gutmans, the Zend
Engine is anabbreviation of their names. Now Zend engine 2 is used by PHP5.

Coming back to Zend engine again.
The PHP script was loaded by the Zend Engine and compiled
into Zend opcode. Opcodes, short for operation codes, are low level binary
instructions. Then the opcode was executed and the HTML
generated sent to the client. The opcode was flushed from memory after

Now we’ll be briefly discussing about new features of PHP5.

An Introduction to PHP – PHP 5 Features

* Vastly improved object-oriented capabilities:
The object oriented features of PHP5 makes it an instant success.
The version5 includes numerous functional additions such as explicit constructors & destructors,
object cloning,class abstraction,variable scoping,interfaces,and a major improvement in object management

The VAR keyword for identifying class properties became deprecated and will throw an E_STRICT warning.

PHP Strict Standards: var: Deprecated. Please
use the public/private/protected modifiers in
obj.php on line 3.

Instead, you should use PUBLIC, PRIVATE or PROTECTED keywords

To copy an object in PHP 5 you need to make use of the clone keyword.

This keyword does the job that $obj2 = $obj; did in PHP 4.
Being a keyword, clone supports a number of different, but equivalent syntaxes.
class A { public $foo; }

$a = new A;
$a_copy = clone $a;
$a_another_copy = clone($a);

$a->foo = 1; $a_copy->foo = 2; $a_another_copy->foo = 3;

echo $a->foo . $a_copy->foo . $a_another_copy->foo;
// will print 123
__clone() can be extended to further modify the newly made copy.
class A {
public $is_copy = FALSE;

public function __clone() {
$this->is_copy = TRUE;
$a = new A;
$b = clone $a;
var_dump($a->is_copy, $b->is_copy); // false, true

U can declare FINA classes and methods in PHP 5
For methods it means that they cannot be overridden by a child class.

Classes defined as final cannot be extended.

U also have a __autoload() function in PHP%

function __autoload($class_name) {
require_once “/php/classes/{$class_name}.inc.php”;
$a = new Class1;

The function will be used to automatically load any needed class that is not yet defined.

Objects in PHP 5 can have 3 magic methods.

__sleep() – that allows scope of object serialization to be limited. (not new to PHP)

__wakeup() – restore object’s properties after deserialization.

__toString() – object to string conversion mechanism.

* Try/catch exception handling: u can handle the error using exception handling mechanism

* Improved XML and Web Services support: XML support is now based on the libxml2 library, and a new and rather promising extension for parsing and manipulating XML, known as SimpleXML, has been introduced. In addition, a SOAP extension is now available. Now we’ll see bit about SOAP

SOAP -Simple Object Access Protocal
This is a lightweight XML-based protocol for exchanging structured information between distributed applications over native web protocols, such as HTTP. SOAP specifies the formats that XML messages should use, the way in which they should be processed, a set of encoding rules for standard and application-defined data types, and a convention for representing remote procedure calls and responses.

* Native support for SQLite: PHP5 supports SQLite database server. SQLite offers a convenient solution for developers looking for many of the features found in some of the heavyweight database products without incurring the accompanying administrative overhead.

This is all about the newly added features of PHP5..


Read Full Post »

What is phpUnit?
PHPUnit is a unit testing framework for the PHP programming language. Created by Sebastian Bergmann, PHPUnit is one of the xUnit family of frameworks.

Why phpUnit?

To make code testing viable, good tool support is needed. This is where PHPUnit comes into play. It provides a framework that makes the writing of tests easy as well as the functionality to easily run the tests and analyse their results.

its better to install phpUnit with WAMP or XAMPP in your system
In my case I have a xampp installation in my sytem . if you dont have a xampp already installed in your system, here is how you can do it.

Installing XAMPP

* Download XAMPP from http://www.apachefriends.org/en/xampp.html
* Unpack the zip, don’t run any installer, just use the \xampp\xampp-control.exe to control the component (so the whole XAMPP directory can be moved to another drive without having absolute paths in all configurations files)

phpUnit needs the pear package installed in yout php

so let start installing PEAR
* Execute  \xampp\php\go-pear.bat and follow the onscreen instructions. The installation will modify the include_path in your php.ini file.
* Execute \xampp\php\PEAR_ENV.reg to add PEAR to the windows registry

Installing PHPUnit
* Open a command prompt (cmd in windows)
* Execute  pear channel-discover pear.phpunit.de
* Execute  pear install phpunit/PHPUnit
* Now you should find PHPUnit installed in \xampp\php\PEAR\PHPUnit\

And your phpUnit is ready to roll!!

Read Full Post »

It’s something interesting that we encountered today with Alfresco…..

We were working with GROUPS in Alfresco Web Client through “Admin Console” i.e. Trying to create new groups and add an existing group with in this new group and Alfresco complained about it with  the message –

A group ID with the same name already exists, group identifiers must be unique.

Now if you try to do the same thing through the “Admin Console” in Share what Alfresco does is that if you have any already existing group (say GROUP_A) and you create a new group (say GROUP_B) and if you try to create a sub-group under GROUP_B (say GROUP_A already created above) then Alfresco will move the already existing GROUP_A under GROUP_B.

Read more  here.

Read Full Post »

SURF helps you to build user interfaces for your Web Applications using server-side scripts and templates.

Alfresco Share is the best example for its implementation and the other one is Activison’s DAM (Digital Asset Management) system.It’s the first application to be developed on SURF at the Enterprise level and I feel really proud to work on with it. I would like to thank Timothy Bergeron and Jeremy Osterloh at Activision for all their support and help in making me learn SURF.

The best thing I like about SURF is no JAVA coding(yes really no java coding….), no recompilation and no server restarts. You just need a text editor and there you are ready to make changes to live site. It provides features such as Scripts & Templates, Reusability,Spring Web MVC, Content Management, 2-tier mashup architecture.

As a developer you need to look into SprinRoo a light weight developer tool released by SpringSource community.

You may read more information @ http://wiki.alfresco.com/wiki/Spring_Surf

It is the dynamic information that the web application looks to at runtime to inform its decision about what to render or how to render.
A Spring Surf Web Application may have two kinds of dynamic content – Semantic Content & Presentation Content. These both together inform SURF of what to render as well as how to render .

Semantic Content It consists of documents or files that may describe business-generated content. Such content are authored, approved and published. e.g. A Contact Detail content to be displayed on the home page.
Semantic Content can be thought of as information that describes what should be rendered. It contains the approved messaged but it doesn’t contain any formatting information. The data may be in pure data format such as JSON or XML. Consider my contact details in JSON format as
“contact_name”    :    “Sujay Pillai”,
“contact_number”:    “8008882182”,
“designation”    :    “Software Engineer”,
“organization”    :    “Zensar Technologies Ltd.”

Presentation ContentIt consists of documents and files that descibe presentation configuration for a Web Site. It contains all the configurations that informs the SURF rendering engine how the Web page or page component should look and feel.

It contains answers to questions from Semantic Content such as –
1) Which theme should be used to render the Web site’s home page?
2) How many contacts should I display on the front page?
3) For a current user which advertisement should be displayed?

It answers the question of how things should be rendered.

Consider the following XML configuration that is responsible for rendering the Global header in “Alfresco Share” –

Consider the scenario when you hit the login button on Alfresco Share –
1. The browser request arrives to Spring Surf.
2. Surf asks the content delivery services for the presentation content that describes what is being requested.
3. The presentation content is handed back as XML.
4. Surf determines the Web Script to execute and does so using the configuration specified by the XML.
5. The Web script calls over to the content delivery services and asks for header data.
6. The header is returned as HTML.

Read Full Post »