Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, January 7, 2008

Delphi PHP

I have already post about php which is like delphi, I have made some changes, you can download it for free here .
And please review to make it perfect.

Tuesday, May 8, 2007

require vs include

php, to combine scripts from several files is by using statements include,
include_once,require and require_once.
So, what's the different between them ?

include vs include_once:
I will describe it by refering to the following example:

suppose we have a file one.php consist of code:
echo "Welcome to the jungle"

and we have a file two.php consist of code:
echo "By Tarzan"

then we like to combine one.php code into two.php
with code like this:

include("one.php");
include("one.php");
include("one.php");
echo "By Tarzan"

the result would be :

Welcome to the jungle
Welcome to the jungle
Welcome to the jungle
By Tarzan


if the we change the code like this:
include_once("one.php");
include_once("one.php");
include_once("one.php");
echo "By Tarzan"

the result would be :

Welcome to the jungle
By Tarzan

because 'include_once' would eliminate all of same values and would display
once, while 'include' would display all of them many times depend on how
many times one.php was repeated


require vs require_once:
the same as include vs include_once


include vs require:
viewed from the function of combining code, both of include and require is
same.
the different is when error occure, 'require' would not execute all of the
next codes , while 'include' would execute.


that's all :)

Friday, May 4, 2007

PHP Class

I found a great thing in PHP 5, which is the real class concept has already
adopted ( similar to other language like delphi). So that, OOP (Object
Oriented Programming) can be implemented very well.

In general, PHP class has structure like this

class aname() {
//definition of variable, in delphi called property
var ....

//constructor, in delphi would be Create
function __constructor(){
//initial value should be placed here
......
}
function a(){
...
}
function b(){
....
}
}


Ideally, a class should be has Get and Set method
Get is to retrieve data from a class
Set is to place data into a class

example:

class person() {
var $IdentityNo,
$Name;

function __construct(){
$this->$IdentityNo="";
$this->$Name="";
}

function GetIdentityNo(){
return $this->$IdentityNo;
}
function GetName(){
return $this->$Name;
}

function SetIdentityNo($AIdentityNo){
$this->$IdentityNo=$AIdentityNo;
}
function SetIdentityNo($AName){
$this->$Name=$AName;
}
}

usage:

$p=new person; //construc
$p->SetIdentityNo("001"); //Set Identity No
$p->SetName("Paijo"); //Set Name

echo $p->GetIdentityNo(); //print Identity No
echo $p->GetName(); //print Name


that's a simple, right :)