Feeds:
Posts
Comments

Archive for the ‘PHP’ Category

Benefits of desktop development

There are a number of benefits to desktop development, from technical advantages to fundamental benefits. Here are some reasons why you should be developing desktop applications.

Technical advantages

There are a number of basic technical advantages to desktop-based applications. They can interact with the local filesystem, allowing settings to be saved on the user’s computer, files to be retrieved and manipulated, databases to be stored and so on. They generally integrate with the GUI toolkit of the operating system, providing a UI style that the user is familiar with – users are still getting used to the web application interfaces of our web 2.0 applications. And finally, they use consistent interfaces, unlike the hope-for-the-best approach to writing HTML, allowing for complex UI elements.

Fundamental advantages

However, perhaps most importantly, they are geared to user-driven applications, especially where the user has content to share. Web applications can easily bring users together, for effective sharing of information.Desktop applications, on the other hand, can easily work with the user and manage information, especially when there is no need to share that information.

Gaming is an excellent example; interface and graphics issues aside, games are built around the user, and as a result work very well on the desktop. Image editing is another; despite the availability of online Photoshop alternatives, everything at the higher end of image editing is still squarely on the desktop. Sure, there’s
Flickr, but Flickr is more geared towards the sharing of photos and basic editing.

As a result, if you’re considering building an application that fits into one of these categories, and you’ve
currently got a web application in mind, a desktop application is definitely worth considering.

To demonstrate basic application development in PHP, we’ll take a look at the PHP-GTK extension. PHP-GTK offers GTK bindings for PHP, allowing you to build scripts that create windows using the GTK
graphics toolkit.

What is PHP-GTK?

GTK is an acronym for the GIMP Toolkit and GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paint shop. It’s the graphics editor of choice for most Linux users.

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:

1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you’re thinking along the lines of MFC for C++ then you’re making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API’s from the developer. GDK does the same thing for GTK+.

Where to get?

We can download binary as well as source code version of PHP-GTK from http://gtk.php.net/download.php . As a beginner, it would be a difficult process to download and install in this manner. Where we need to set up another php.ini file for PHP-GTK. Instead there is another way of installing it. We can get PHP-GTK2 in an executable form as we get WAMP.EXE. (Windows, Apache, Mysql, PHP) All we have to do is just download just download the files from http://www.gnope.org/download.php ,unzip them and double click on the icon GnopeSetup-1.5.1.exe . It will run through a step by step process where it will set up PHP-GTK automatically.
How to test the installation?

Once the installation is done we would eager to know about what is special in it? When we install PHP we would run phpinfo () from root directory .For this let us run a sample script which displays Hello world (as usual) .we can use Dreamweaver for editing the code. Another important point to be kept in mind is to save the file with extension .phpw it can be saved anywhere on your hard disk.

Here is the sample code:

set_title(‘Hello world’);
$wnd->connect_simple(‘destroy’, array(‘gtk’, ‘main_quit’));
$lblHello = new GtkLabel(“hello world”);
$wnd->add($lblHello);
$wnd->show_all();
Gtk::main();
?>

I have saved this sample file with the name hello.phpw at c:\test\. We should run this sample code from command line interface. (CLI) There may be a question rising in your mind asking, why we should run through command prompt than by just by double clicking it as it is a stand alone application. It is possible, for that we need to have a PHP compiler which converts our PHP-GTK code to EXE file . For now, let us try running it from the command prompt.

Steps for Executing a sample code:

1. Start -> Run -> cmd (for xp sp2 and later version) or command (for windows 98).
2. Now you could see a black window which is Command Prompt. Key in the following commands as shown below.

z:>c:
c:> cd test
c:\test>php hello.phpw

Once we finish this line and hit the Enter key, we should see the desired output.

This shows the successful installation of PHP-GTK2 and shouls us PHP output without a web-browser.

Some interesting Websites on PHP-GTK:

1. http://www.kksou.com/php-gtk2/
2. http://phpgtk.activeventure.com/gtk/gtk.gtkbox.html (describes about all base classes).
3. http://gtk.php.net/download.php
4. http://www.gnope.org/download.php

Advertisements

Read Full Post »

(more…)

Read Full Post »

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
execution.

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%

?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 »