php class is not visible to outside file - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, August 30, 2023

php class is not visible to outside file

i have 2 php files as part of a website one have the api functions (pre made ready to use requests) the other have the code it self that i want to call these functions from

the api file looks like :

<?php
class API_REQUESTS {
    public static function GetSomeData() {
        return some_request('some_url');
    }
}
?>

and the other file that i want to include the api at looks like :

<?php
include '..\path\to\api\api.php';

echo API_REQUESTS.GetSomeData();
?>

very simple at the moment

now when running : first my setup is iam using XAMPP and it should be setup correctly sense everything works fine except for the php file it self

when it runs it gives me an error

Fatal error: Uncaught Error: Undefined constant "API_REQUESTS" in "path\to\index.php":3 Stack trace: #0 {main} thrown in "path\to\index.php" on line 3

i said maybe i made a mistake in the include path but when trying to change it it gives me a new Warning: include 'wrong\path' Failed to open stream: No such file or directory

so the path is right

i also tried using "require" and "require_once" but same problem



source https://stackoverflow.com/questions/77002710/php-class-is-not-visible-to-outside-file

No comments:

Post a Comment