Need help with class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
standerby
Forum Newbie
Posts: 2
Joined: Tue Jan 22, 2008 11:56 am

Need help with class

Post by standerby »

I want to include class in one php page. However I couldn't get it working? I didn't get any error message but I didn't get the html page either. Any one could help me? Thanks.

***** PLEASE USE THE [CODE] TAG *****

Code: Select all

<?php
function __autoload($class)
{
    if (file_exists($file = "$class.php"))
    {
        include($file);
    }
    else
    {
        throw new Exception("Class $class not found");
    }
}
 
try
{
    class_exists('pd');
    $remo = new pd();
 
?>
<html>
<head>
</head>
<body>
<div id='div1'>test<br />
<?php
        print $remo.test();
        print "sssssss";
    }
        catch (Exception $e)
        {
            // Catch the exception and handle it as usual
            throw new Exception($e->getMessage());
        }
?>
 
</div>
</body>
</html>
 
pd.php
class pd{
    private $dsn;
    
    function _pd() {
        $dsn = 'mysql://pd:password@127.0.0.1/pd';
    }
        function test(){
            return 2;
        }
}
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Need help with class

Post by Zoxive »

Always turn on Error Reporting When Debugging.

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors',true);
standerby
Forum Newbie
Posts: 2
Joined: Tue Jan 22, 2008 11:56 am

Re: Need help with class

Post by standerby »

Thanks.
Post Reply