Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-2007, 09:57 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,228
Last Blog:
Passwords
Credits: 857
Rep Power: 20
John has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud ofJohn has much to be proud of
Send a message via AIM to John
Default Instantiating a Class

Classes are great, but how do we use them? As with any programming language, the classes have to be instantiated, and the objects have to be created. The first step required is to require the file.

PHP Code:
<?php
require_once("HelloWorld.class.php")

?>
This assumes we have a php class named HelloWorld.class.php. As a side note, it is a convention to name your class files with the .class extension, however since they are usually listed in public directorys on the internet, adding the .php extension after the .class extension prevents your code from being viewable, which is an extra security precaution you should take.

Anyway, once we have included the contents of the file, we want to instantiate it. We do this by using the new keyword, moreover you usually asign it a variable:

PHP Code:
$hello = new HelloWorld(); 
Now if the HelloWorld class contains public functions we can call then using " -> ". Lets assume the HelloWorld class has a function called HelloCodeCall that looks like this:

PHP Code:
function HelloCodeCall() {
    echo 
"Hello CodeCall users!";

To call that function you do this:

PHP Code:
<?php
require_once("HelloWorld.class.php")
$hello = new HelloWorld();
$hello->HelloCodeCall();
?>
And that will print the content of the constructor and the content of HelloCodeCall.
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assignment Lestat C and C++ 8 09-18-2007 02:20 PM
Issue writing to file: pointer to a class which contains pointers to other classes Sheemer C and C++ 0 08-21-2007 01:17 AM
Java:Tutorial - "Hello World" John Java Tutorials 10 07-17-2007 04:58 PM
need help on class project javic Java Help 4 02-19-2007 03:31 PM
Java Help Files xXHalfSliceXx Java Help 3 11-28-2006 11:30 PM


All times are GMT -5. The time now is 04:44 PM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1047.22
marwex89 ........ 869.98
morefood2001 ........ 868.04
John ........ 857.15
WingedPanther ........ 761.06
Brandon W ........ 684.41
chili5 ........ 294.12
dargueta ........ 192.86
Steve.L ........ 192.06

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads