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

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




Advance function in php Part 2

 
Reply to this topicStart new topic

Advance function in php Part 2

myharshdesigner
19 Jan, 2008 - 07:48 PM
Post #1

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
1st here is my folder structure :-

CODE

demo
|
|-demo1.php
|
|-ok
  |
  |-MyClass1.php
  |
  |-MyClass2.php







demo1.php code:-
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();
?>



MyClass1.php code:-
CODE

<?php
class MyClass1
{
    function show1()
    {
        echo("yahoo it is demo1");
    }
}
?>



MyClass2.php code:-
CODE

<?php
class MyClass2
{
    function show2()
    {
        echo("love you pyar say");
    }
}
?>



when i try to call that demo1.php i got error :-

CODE

Warning: include_once('ok/MyClass1.php') [function.include-once]: failed to open stream: No such file or directory in D:\xampp\htdocs\Web\demo\demo1.php on line 7

Warning: include_once() [function.include]: Failed opening ''ok/MyClass1.php'' for inclusion (include_path='.;D:\xampp\php\pear\') in D:\xampp\htdocs\Web\demo\demo1.php on line 7

Fatal error: Class 'MyClass1' not found in D:\xampp\htdocs\Web\demo\demo1.php on line 9



i dont know why ?
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Advance Function In Php Part 2
19 Jan, 2008 - 09:36 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,260



Thanked: 227 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I am not sure why you are using such a complicated path concatenation, but I think the extra single quotes are causing a problem. I say this because of your second error line there where it reads... Failed opening ''ok/MyClass1.php'' for inclusion Notice how the file it says have two single quotes on each side?

Try this in your autoload...

CODE

include_once("ok/{$class_name}.php");


This way we evaluate the variable inside the double quoted string. Hopefully that will help. smile.gif
User is offlineProfile CardPM
+Quote Post

myharshdesigner
RE: Advance Function In Php Part 2
20 Jan, 2008 - 05:12 AM
Post #3

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
is it so ?
User is offlineProfile CardPM
+Quote Post

myharshdesigner
RE: Advance Function In Php Part 2
20 Jan, 2008 - 11:58 PM
Post #4

New D.I.C Head
*

Joined: 26 Dec, 2007
Posts: 24


My Contributions
ya you r right it' working now smile.gif

Thanks.
User is offlineProfile CardPM
+Quote Post

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

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