Welcome to Dream.In.Code
Become a PHP Expert!

Join 137,427 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,891 people online right now. Registration is fast and FREE... Join Now!




Advance function in php Part 3

 
Reply to this topicStart new topic

Advance function in php Part 3

myharshdesigner
21 Jan, 2008 - 06:45 AM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
CODE

<?php

$url = "ok/";

function __autoload($class_name)
{
    include_once("ok/".$class_name.".php");
}
$obj = new MyClass1();
$obj2 = new MyClass2();

$obj->show1();
echo "<br>";
$obj2->show2();
?>



in this example :-

__autoload is user define or predefine function ?


this function can work in php4 ?
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Advance Function In Php Part 3
21 Jan, 2008 - 08:13 AM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,550



Thanked: 67 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
It looks to me like the function is question (__autoload) is only used to load another php page from the include directory. When __autoload is called, it can be passed a class name, then that class is loaded (include_once) from the ok directory.

What is interesting to me is that the variable $url is defined but then not used when it could have been.

CODE

$url = "ok/";

function __autoload($class_name)
{
    include_once("ok/".$class_name.".php"); // <-- if $url is changed, then this piece of code is still hard-coded to point to the directory.


I hope this helps answer your question.
User is offlineProfile CardPM
+Quote Post

myharshdesigner
RE: Advance Function In Php Part 3
21 Jan, 2008 - 08:56 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
when i use this code i m getting an error.

my file which is on server is producing some error:-

Fatal error: Cannot instantiate non-existent class: myclass1 in /home/twtvindia/domains/kamaldigitallab.com/public_html/demo/demo.php on line 6

i cant able to understand so pl help me to solve this problem.


Thanks
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Advance Function In Php Part 3
21 Jan, 2008 - 09:23 AM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,550



Thanked: 67 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(myharshdesigner @ 21 Jan, 2008 - 09:56 AM) *

when i use this code i m getting an error.

my file which is on server is producing some error:-

Fatal error: Cannot instantiate non-existent class: myclass1 in /home/twtvindia/domains/kamaldigitallab.com/public_html/demo/demo.php on line 6

i cant able to understand so pl help me to solve this problem.


Thanks

Is there a file "ok\myclass1.php" ??

Again, it looks to me as if the function __autoload takes an argument of the class name. It then tries to load another php file from the directory ok, with that as the file name.

so if you call __autoload(myclass); it is going to try to load "ok\myclass.php".

I hope this helps.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:47AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month