Usage of class in PHP from different directory -
i have been using classes in php.
i have directory, test, in there index.php sub-directory test new, has checkuser.php code checkuser code:
<?php public class checkuser{ public function checkuser() { echo "this class"; } } ?>
code index.php:
<?php include('new/checkuser.php'); ?> <html> <head> </head> <body> <?php checkuser::checkuser(); ?> </body> </html>
but throws error. please help.
what kind of error that?
there more things:
you declaring class "public"
parse error: syntax error, unexpected t_public on line 2
you calling non-static method statically
fatal error: non-static method checkuser::checkuser() cannot called statically on line 17
you including file, without being aware of context, suggest practice:
<?php include( dirname(__file__) . '/new/checkuser.php'); ?>
or if using php > 5.3
<?php include( __dir__ . '/new/checkuser.php'); ?>
and here how code work:
<?php class checkuser { public static function myfunction() { echo "this class"; } } ?> <html> <head> </head> <body> <?php checkuser::myfunction(); ?> </body> </html>
note: of course, can split code in more files, make sure specify path seen above, can find actual file
Comments
Post a Comment