Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 14th, 2005, 02:03 AM
vijaykoul vijaykoul is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 12 vijaykoul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 m 22 sec
Reputation Power: 0
Using classes in PHP

Hi everybody,

I know that this room is for ASP development but as i found no PHP discussion room, I will be happy if anybody among
you will help me solve this problem.

I was trying to work with classes in PHP
Although they are similar in making to classes in other languages, but I faced one problem.

The code for the class is as follows:

<?php
class Page {
var $Title;
var $Keywords;
var $Content;

function disp( )
{
echo "<HTML>\n<HEAD>\n";
echo "\n</HEAD>\n<BODY>\n";
$this->Title="My First Page";
echo $this->Title;
echo "\n</BODY>\n</HTML>\n";
}
function main()
{
$objP= new Page;
$objP->disp( );

}
}
?>

I saved thisfile as classes.php and tried to run it, however I got no output.
Then what I did was that I saved this file as '.class' file and created another file named P1. php.
Code of that file is as follows:
<?php
include "classes.class";

$objP= new Page;
$objP->disp( );
?>

this time it worked fine and i also got the output right.
I have a few questions in mind.
1. Is it necessary to create '.class ' file and then call it in other file to execute classes in PHP
2. Is there anything wrong with my coding in classes.php file that maked it not work exactly I wished to.

or is there any other problem.

I'll be highly thankful to anybody whos provides me its solution

vijay

Reply With Quote
  #2  
Old February 14th, 2005, 02:31 AM
Lafinboy's Avatar
Lafinboy Lafinboy is offline
The Laughing Moderator
ASP Free Loyal (3000 - 3499 posts)
 
Join Date: Apr 2004
Location: Sydney, Australia
Posts: 3,267 Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)Lafinboy User rank is Sergeant (500 - 2000 Reputation Level)  Folding Points: 29199 Folding Title: Starter FolderFolding Points: 29199 Folding Title: Starter Folder
Time spent in forums: 2 Weeks 1 Day 10 h 48 m 12 sec
Reputation Power: 15
Send a message via ICQ to Lafinboy Send a message via AIM to Lafinboy Send a message via MSN to Lafinboy Send a message via Yahoo to Lafinboy Send a message via Skype to Lafinboy
A class is simply a collection of functions and subroutines (object) that are relevant to a particular group or type of actions, eg database classes generally hold functions to connect to, update, insert, delete, create and various other sql actions. You need to initialise class and call the class functions to have some affect from them. The class itself will not perform any action on it's own.

Quote:
Originally Posted by lafinboy
This thread has been moved from the ASP forum to the Code Help forum.

Reply With Quote
  #3  
Old February 14th, 2005, 05:16 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 46th Plane (27500 - 27999 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,737 Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1Folding Points: 377762 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 5 h 41 m 46 sec
Reputation Power: 1914
you better post your question in PHP forum, this is aspfree.com forums thus most members don't know php and can't help very much with the code.

Reply With Quote
  #4  
Old February 19th, 2005, 03:29 PM
Phoenix's Avatar
Phoenix Phoenix is offline
Web-Standards Evangelist
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2003
Posts: 1,522 Phoenix User rank is Corporal (100 - 500 Reputation Level)Phoenix User rank is Corporal (100 - 500 Reputation Level)Phoenix User rank is Corporal (100 - 500 Reputation Level)Phoenix User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 23 h 48 m 4 sec
Reputation Power: 9
PHP classes are a way of reusing common code. If you want a simple PHP page just write plain HTML in a *.php file.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Using classes in PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT