开发者

Class Not Found, but its static methods work

I've stared at this for two hours, and I'm sure there's a decent reason this is happening, but I can'开发者_StackOverflow中文版t figure it out.

<?php
error_reporting(7); //warning & parse

include($_SERVER['DOCUMENT_ROOT'].'/echo/EchoApplication.php');


$db_credentials = array(
    'host'          => 'localhost',
    'user'          => 'db_user',
    'password'      => 'db_pass',
    'database'      => 'db_name'
);

EchoApplication::testMethod();

$app = new EchoApplicaton(); //line 16
$app->db_credentials = $db_credentials;
$app->run();
----and this happens----
Fatal error: Class 'EchoApplicaton' not found in /var/www/html_echo/page.php on line 16

How is that possible?

EDIT: posted the whole page's code.


EchoApplicaton

You've missed one letter - EchoApplicat >>i<< on


Are you sure your class has a constructor? I think the new statement doesn't work if you are missing one.

According to the manual:

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class. Effectively, it means that the only case that would have compatibility issues is if the class had a method named __construct() which was used for different semantics.

Basically, you better either have a __construct() or a EchoApplicaton() method in your class that is publicly accessible, or an error will be thrown.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜