Archive for January, 2008

$this variable & self class name

$this is a special variable of an object. Using $this, a member variable or methods of the class can be accessed from anywhere inside of that class.

self is a reserve class name which is also used inside the object itself.

For the static members and static methods and constants, self class name is used instead of $this. So when you use static method or variables and call it inside the same class you must use the self not the $this.

Leave a Comment

Joomla 1.5 Stable Version has Released

It’s a big day for hundreds of thousands of web sites built on top of the popular open-source Joomla! CMS. After over two years of development and reworking, Joomla! 1.5 (stable) has released to the user community today, combining a brand new object-oriented PHP framework with the content management system’s ease of use and its multitude of functional extensions. You can download it from here

Comments (3)

Singleton Pattern in PHP

Singleton design pattern is used to control the instantiation of a class to an Object. The singleton pattern is implemented by creating the class with a method that creates an instance if one does not exists and the constructor of the class is private.

We can implement this in PHP-5 as followings

<?php

class Singleton {

// object instance

private static $instance;

//constructor
private function __construct() {}

//clone
private function __clone() {}

//make instance
public static function getInstance() {

if (self::$instance === null) {//checking the previous instance

self::$instance = new self;

}

return self::$instance;

}

//the other methods of this class

public function doAction() {

}

}

?>

<?php

//usage

Singleton::getInstance()->doAction();

?>

In this example we can see that a static variable $instance is declared to hold the instance of the class. Also the constructor and clone method is private, this ensure the controlling of making the new object of that class.

After that we make a public function getInstance to make an instance of the class. This function return a new instance if no instance of the class is not exists, if exists this return that instance.

AND the uses is simple just use $class_name->getInstance() to make a new instance of the class.

Thanks

Comments (2)

Behavior isset, empty and casting of a variable as boolean in if statement

Suppose you want to check a variable is available or not. Then we can use the following

1. using isset:

if(!isset($var)){

//do something

} else{

//do something

}

2. Using empty:

if(!empty($var)){

//do something

} else{

//do something

}

3. Using the Implicit casting facility

if($var){

//do something

} else{

//do something

}

Now explanation and others

1. the isset function just check only if the variables is set(defined/declared) or not. If defined then return true else return flase. But this don’t check that the variable has a value or empty. So you should be careful to use this function. example:

isset($var);// this will return false

—————-

$var =  ‘test’;

isset($var);//this will return true

———-

$var = ”;

isset($var) //this will also return true

2. if u use empty then
Returns FALSE if $var has a non-empty and non-zero value.

The following things are considered to be empty:

“” (an empty string)
0 (0 as an integer)
“0″ (0 as a string)

and this is an opposite of (boolean)$var.

3.  Casting of the variable

if you use the casting then it will work as empty method but warning is generated when the variable is not set.

****As of PHP 5, objects with no properties are no longer considered empty

Leave a Comment

Some Issues You must have to Know as a PHP Developer

Ist Thing:

PHP was written by the Danish/Greenlandic programmer Rasmus Lerdorf in 1994 to maintain his personal homepage and named it as Personal Home Page Tools. After Lerdorf combined it with his own Form Interpreter to create PHP/FI (this release is considered PHP version 2).

Zeev Suraski and Andi Gutmans, two Israeli developers at the Technion IIT, rewrote the parser in 1997 and formed the base of PHP 3, changing the language’s name to the recursive initialism PHP: Hypertext Preprocessor. The development team officially released PHP/FI 2 in November 1997 after months of beta testing. Public testing of PHP 3 began and the official launch came in June 1998. Suraski and Gutmans then started a new rewrite of PHP’s core, producing the Zend Engine in 1999. They also founded Zend Technologies in Ramat Gan, Israel, which actively manages the development of PHP.

The Histories of PHP:

Version Release date Most important changes
PHP 1.0 June 8, 1995 Officially called “Personal Home Page Tools (PHP Tools)”. This is the first use of the name “PHP”.
PHP Version 2 (PHP/FI) April 16, 1996 Considered by its creator as the “fastest and simplest tool” for creating dynamic web pages .
PHP 3.0 Jun 6, 1998 Development moves from one person to multiple developers. Zeev Suraski and Andi Gutmans rewrite the base for this version.
PHP 4.0.0 May 22, 2000 Added more advanced two-stage parse/execute tag-parsing system called the Zend engine.
PHP 4.1.0 Dec 10, 2001 Introduced the superglobals ($_GET, $_POST, $_SESSION, etc.)
PHP 4.2.0 April 22, 2002 Disabled register_globals by default
PHP 4.3.0 Dec 27, 2002 Introduced the CLI, in addition to the CGI
PHP 4.4.0 July 11, 2005  
PHP 5.0.0 July 13, 2004 Zend Engine II with a new object model.
PHP 5.1.0 Nov 24, 2005 Performance improvements with introduction of compiler (CV) variables in re-engineered PHP Engine.
PHP 5.2.0 Nov 2, 2006 Enabled the filter extension by default

Please check http://en.wikipedia.org/wiki/Php

Comments (1)

Create an Application with Codeigniter: Part -1 (installing CodeIgniter)

Due to heavy traffic on CodeIgniter, I have decided to put a tutorial on CodeIgniter. To create an application with CI(codeigniter), first step is installing the framework.

To install codeigniter you need to take the following steps:

Step 1: Get the latest version of the Codeigniter. You can download the framework form http://codeigniter.com/download.php

Step 2: Unzip the Package

Step 3: Put the codeigniter folders and its files into your web root..

Step 4: Configure Your Base URL: To configure your base URL open “system/application/config/config.php” to edit. then change this line

$config['base_url']    = “”;

to

$config['base_url']    = “http://www.yoursite.com/”;

One thing You must have to put a trailing slash in the URL.

Step 5: Configure Your database: Now if you wan to use a database then open “system/application/config/database.php” to edit.

Then change these lines

$db['default']['hostname'] = “localhost”;
$db['default']['username'] = “”;
$db['default']['password'] = “”;
$db['default']['database'] = “”;
$db['default']['dbdriver'] = “mysql”;
$db['default']['dbprefix'] = “”;

As Your configuration.

Thats it.

Now visit http://www.yoursite.com/

What do you see??

Leave a Comment

Regular Expression(RegEX) Tutorial

There are tons of Regex tutorials in the web.

But i found this one is best for me.

You can check it here

This is divided into two parts. Every parts are really Great.

Hope this will also help you.

Leave a Comment

Configuring Virtual host in Apache in Windows

Configuring a Virtual host in Apache in windows needs just two step.

First one: configure the apache

Second one: configure the DNS in windows.

First One:

The first file we’ll need to edit is the Apache httpd.conf file. Start your text editor and open the file. It will be in a sub-folder named conf of your Apache folder. For example, mine is here:

C:\Program Files\Apache\conf\httpd.conf

Now, for this example, we’ll assume that you have your web sites located in a folder on your C drive. Each web site has a sub-folder of its own under that folder, like this:

   C:\test

We’re going to set up virtual hosts for those the site using the domain name test.local. That way, you’ll be able to tell at a glance whether you’re looking at the live site, or your testing site.

In reality, you can call the domain anything you want. You could just as easily name them test.com or test.net. I choose to use the convention of using the same domain name along with the .local TLD to simplify and minimize the typing needed to switch between the live site and the testing site. The only important point, and it’s really important, is that you NEVER use an actual, real, live domain name. If you used, for example, test.com for the local virtual host, you would never be able to actually reach the live site. All requests for the live site would be re-directed to your local virtual host.

Go to the very bottom of your httpd.conf file in your text editor. You should see an example of a virtual host there. Each line of that example will begin with an octothorpe (#). The octothorpe character marks the line as a comment, so the example is not executed. Add the following lines below that example:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
   DocumentRoot "C:\test"
   ServerName test.local
</VirtualHost>

That’s all you need to do! Save and close the file. That will tell the Apache server everything it needs to know in order for it to serve the pages using the domain names test.local.

Second Change:

Obviously, if you typed http://test.local in your browser, it would not be found by your Internet provider’s DNS server. We’re next going to edit another file to work around that. The second file you need to edit is called hosts, with no file extension. It is a Windows system file and it will enable you to enter specific addresses for specific domains instead of using a DNS lookup. The normal location for this file is:

C:\WINNT\system32\drivers\etc\hosts

If you don’t find it there, do a search in your windows directory for the word hosts in the file name. The file you want is called hosts, with no file extension. The correct file will begin with the following lines:

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.

Once again, in this file, the octothorpe character is a comment marker. Lines beginning with it are comments. In all likelihood, there will be nothing there, except for comments. If there are any other non-commented entries, leave them alone. Just go to the bottom of the file, below all the comments and any existing entries and add the following two lines:

127.0.0.1 test.local

That’s all you need to do there. Save and close the hosts file.

Lastly :

You’re almost done! The only remaining thing you need to do is to re-start the Apache server. You need to do this because Apache only reads the configuration file when it first starts up

Hope this will work for you.

Comments (2)

Difference Between InnoDB and MyISAM

  • The big difference between MySQL Table Type MyISAM and InnoDB is that InnoDB supports transaction
  • InnoDB supports some newer features: Transactions, row-level locking, foreign keys
  • InnoDB is for high volume, high performance

Most people use MyISAM if they need speed and InnoDB for data integrity. You can use more than one or any combination of these table types in your database. Remember to asses the needs of your application before building it. Even though MyISAM is faster than InnoDB in the MySQL world, InnoDB is fast compared to any database engine.With InnoDB you get transactions, speed and integrity three features not usually used in the same sentence.

InnoDB has been designed for maximum performance when processing large data volumes. Its CPU efficiency is probably not matched by any other disk-based relational database engine.

Fully integrated with MySQL Server, the InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files. InnoDB tables can be of any size even on operating systems where file size is limited to 2GB.

So, what do you think about those engines?? Please feel free to discuss it.

For more information visit http://dev.mysql.com/

Thanks

Comments (7)

First code for Facebook Application

The code below is my first Facebook application code.

<?php
// Tapos Pal
//
// Application: justpersonal
// File: ‘index.php’
// This is my first code for facebook
//

require_once ‘./facebook/facebook.php’;
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

// Greet the currently logged-in user!
echo “<p>Hello, <fb:name uid=\”$user_id\” useyou=\”false\” />!</p>”;

// Print out at most 25 of the logged-in user’s friends,
// using the friends.get API method
$friends = $facebook->api_client->friends_get();
$friends = array_slice($friends, 0, 25);
?>
<fieldset>
<legend>Your Friends</legend>
<table>
<tbody>
<?php
foreach ($friends as $friend) {
?>

<tr>
<td><fb:name uid=”<?=$friend?>” useyou=”false” /></td><td><fb:profile-pic uid=”<?=$friend?>” size=”square” linked=”true” /></td>
</tr>

<?php

}
?>
</tbody>
</table>
</fieldset>

And this is the view on Facebook

Facebook Application 1

Comments (2)

Older Posts »