Brent
Brent

Reputation: 23702

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'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.

Upvotes: 2

Views: 1493

Answers (2)

zerkms
zerkms

Reputation: 254944

EchoApplicaton

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

Upvotes: 3

Chris Laplante
Chris Laplante

Reputation: 29658

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.

Upvotes: 0

Related Questions