| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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:
__________________
-
thought-after | my thoughts on web development Get Firefox, the developers browser Budget hosting - recommended [/left] |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
PHP classes are a way of reusing common code. If you want a simple PHP page just write plain HTML in a *.php file.
|
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Using classes in PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|