Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (16 June 2013 - 05:41 PM) You're Welcome, Agyat!
@  agyat : (16 June 2013 - 07:38 AM) Thanks Yordan...
@  velma : (16 June 2013 - 12:06 AM) I Have Asked Opa To Check For A Backup.. He'll Let Me Know Soon :)
@  velma : (16 June 2013 - 12:05 AM) T_T It Seems That Someone Has Deleted That Topic Since I Found The Url Of The Topic But It Gives Me An Error
@  yordan : (15 June 2013 - 10:31 PM) @velma : It's A Tuto On How To Create A Login Program.
@  yordan : (15 June 2013 - 10:31 PM) Happy Birthday To Youuuuuu Agyat!
@  yordan : (15 June 2013 - 10:31 PM) Ba$
@  agyat : (15 June 2013 - 04:41 PM) :(
@  agyat : (15 June 2013 - 04:41 PM) Where The Hall I Were? 15Th Is Almost At End And No-One Wished Me "happy Birthday"!!!
@  velma : (14 June 2013 - 10:39 AM) Which Tutorial Is He Searching For?
@  velma : (14 June 2013 - 10:38 AM) Which Tutorial Is He Searching For?
@  yordan : (14 June 2013 - 07:47 AM) Ok, Have A Look Tomorrow.
@  yordan : (13 June 2013 - 03:19 PM) @velma, Can You Have A Look At Feelay's Problem? Seems That His Tutorial Is Not Searchable Today.
@  Feelay : (13 June 2013 - 08:11 AM) Oh, Haha
@  velma : (12 June 2013 - 05:39 PM) T_T Lately My Levels Of Procrastination..... **sigh**
@  velma : (12 June 2013 - 05:38 PM) I'll Do It Later
@  velma : (12 June 2013 - 05:38 PM) Procrastinators.. People Who Keep Saying "i'll Do This In A Bit"
@  Feelay : (12 June 2013 - 02:05 PM) Deal Punishments To What?
@  velma : (12 June 2013 - 01:27 PM) T_T We Should Deal Punishments To Procrastinators... Especially Me
@  Feelay : (12 June 2013 - 12:06 PM) As Well As Making It More Secure.

Replying to Php Magic Method


Post Options

    • Can't make it out? Click here to generate a new image

  or Cancel


Topic Summary

veerumits

Posted 10 November 2008 - 05:53 PM

PHP 5, have magic method:--

The __autoload() Magic Method:- The __autoload() magic method get automatically called whenever you try to load an object of the class in which resides in separate file and even you have not included those files using any of these method include,require and include_once. but It is neccessary to use the filename as that of the class name.

for example:-
//file name: abc.php;
<?php
class abc{
var $user="Raju";
var $city="delhi";
function xyz(){ echo "Hello ".$this->user." Your city is ".$this->city; }
}
?>
//file name: xyz.php;
<?php
function __Autoload($x){  include_once("$x.php"); }
$obj=new abc;
echo $obj->user."<br>";
echo " &nbsp <br>".$obj->xyz();
?>

output when you brows xyz.php:

Raju
Hello Raju Your city is delhi

here what we see in xyz.php not have any class with the name of abc even i have create here object of class abc,
it is automatically called because i am using magic method __autoload($x), $x is variable which is assign by the name of filename abc and in include _once("$x.php"); it become include _once("abc.php"); so this is magic because it represent something like magic.

both file should be in same directory.

thanks.

Review the complete topic (launches new window)