I'm including a PHP class with
require_once($ENGINE."/classUser.php");
but when the code is executed i receive this error:
Fatal error: Class 'User' not found in C:\xampp\htdocs\WebName\resources\engine\ajax\signup.php on line 12
I still can't figure out what's the problem. I'm 99% sure it's correct.
The "$ENGINE" is correct, and the class is correct too (Netbeans suggests me class methods and variables).
signup.php:
<?php /* Created on: 13/12/2011 * Author: * * Description: User signup procedure. */ require_once("../settings.php"); require_once($ENGINE."/classUser.php"); $user = new User(); $user->createUser($_POST["username"], $_POST["email"], $_POST["password"]); ?>
classUser.php:
<?php /* Created on: 13/12/2011 * Author: * * Description: This class manages users. */ require_once("settings.php"); require_once($LIBRARY."/cassandraphp/cassandra.php"); class User { public function createUser($username, $email, $password){ $cassandra = Cassandra::createInstance($CASSANDRASERVER); $cassandra->set( "user.".$username, array( 'ID' => uniqid(), 'Username' => $username, 'Email' => $email, 'Password' => $password ) ); } } ?>
The spl_autoload_register() function registers any number of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.
The PHP Autoloader searches recursively in defined directories for class, trait and interface definitions. Without any further configuration the directory in which the requiring file resides will be used as default class path. File names don't need to obey any convention. All files are searched for class definitions.
A namespace is a hierarchically labeled code block holding a regular PHP code. A namespace can contain valid PHP code. Namespace affects following types of code: classes (including abstracts and traits), interfaces, functions, and constants. Namespaces are declared using the namespace keyword.
The use keyword has two purposes: it tells a class to inherit a trait and it gives an alias to a namespace.
Check to make sure your environment isn't being picky about your opening tags. My configuration requires:
<?php
If i try to use:
<?
Then I get the same error as you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With