UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Technical Support > Tutorials / How to?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 28-02-2007, 10:09
Junior Member
 
Join Date: Feb 2007
Posts: 15
Cool {PHP} Intro into Classes

Requirements
A WebServer
PHP 4.1.x or higher

So you want to be a php developer or you are already a php developer seeking to learn the missing link. If you have programmed or scripted with any languages such as c++ or asp, youll find they use classses and/or objects in the coding standards.

This option isnt default for php but still an option. Classes are good for alot of things, and it is used for many big projects such as Invision Power Board, this method is known as Object Oriented Programming.

Part I : Writing your first class.

In this example we will be building an extension of the basic echo function. Save this file as echo_class.php

PHP Code:

<?php
class xechos {
################################
#we have the class started now for its contents
###############################
function xechos() {
echo "This is an echo function with a bit of a oop twist";
}
################################
#well thats it, our function.
################################
}
################################
#end the class.
################################
?>

Code Explanation.

PHP CODE:
<?php


Well duh, this starts our php document

PHP Code:

class xechos{

This starts off the class for xechos

PHP Code:

function xecho() {
echo "This is an echo function with a bit of a oop twist";
}

this is the php function xechos, which uses the echo function to bring This is an echo function with a bit of a oop twist.

And thats it you have made your first class.


Part II : Using functions in your class

Youve probably thinking, ok moron, you taught me how to make a class and not to use it, which is why I wrote this section.

add the following to echo_class.php
PHP Code:

<?php
$xechos = new xechos;
$xechos->xecho();
?>

Code Explanation

PHP Code:

$xechos = new xechos;

This declares your class as a var so you can use functions stored in a class. The first parameter is the var name, this doesnt matter as long as its not declared anywhere else, the second would be declaration, which you put new classname, classname being replaced with your actual class of course.

PHP Code:

$xechos->xecho();

This is how you use a function in a class, this bit of code must be used after you declare your class as a var, then you put the var name you decalred you class as, in this example is $xechos, then ->, then the function you want to use.

Your script should have printed out, This is an echo function with a bit of a oop twist, if not then re-read this tutorial cuz you did something wrong

Last edited by Nitro; 28-02-2007 at 10:40.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 17:06.

 

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

VPS Hosting
VPS Hosting plans

Dedicated Server Hosting
Dedicated Server plans

Business Web Hosting
100% uptime Hosting

Cpanel Hosting
cPanel Shared Hosting

Reseller Hosting
Reseller Web Hosting

Windows Hosting
Windows Shared Hosting

Windows VPS

Windows VPS Hosting

Semi Dedicated Servers
Semi-Dedicated Hosting

Dedicated Server Mirroring
Dedicated Server Mirroring

Webhosting Knowledgebase
Frequently asked Questions

Web Hosting Blog
eUKhost Blog

Web Hosting Support
Support Helpdesk

UK Data Center
eUKhost Datacenter

Web Hosting Forum
eUKhost Forum

Support Tutorials
Online Flash Tutorials

Offsite Back-up Plans
Remote Backup Service

Customer Testimonials
eUK Customer Testimonials


knowledgebase articles

eUKhost.com Services

Pre-Sales Questions
Pre-sales FAQ's

Domain Names
Domain registration FAQ's

cPanel Hosting
cPanel Hosting FAQ's

Windows Web Hosting
Plesk Control Panel

Reseller Hosting
Reseller Hosting FAQ's

VPS Hosting
Virtual Private Server

Semi-Dedicated Servers
Semi-Dedicated FAQ's

Dedicated Servers
Dedicated Server Hosting


popular blog categories


Web Hosting
Website Hosting articles

UK Web Hosting
UK Hosting articles

Dedicated Server Hosting
Dedicated Server guidelines

VPS Hosting
VPS hosting articles

cPanel Hosting
cPanel Hosting articles

Linux Operating System
Linux Operating techniques

Windows Web Hosting
Windows plesk articles

Web Hosting
Web Hosting Service