0
book
include
   --lib
     --db.php
     --input.php(static methods)
   --config
      --config.php
      --file.php
index.php

this my folder structure.THe config.php has spl_autoload_register.

spl_autoload_register(function ($class) {
    if (file_exists("lib/{$class}.php")) {
        require_once "lib/{$class}.php";
    }else{
        require_once "include/lib/{$class}.php";
    }
});

i can access classes everywhere from project.but nont from book folder.I used namespace also.its not work for static method.

2
Contributors
1
Reply
23
Views
2 Years
Discussion Span
Last Post by veedeoo
0

I am using the fig-standard auto loader. Pretty much all frameworks today are using the proposed loading standard.

to call static method of class with namespace, you can easily do it like this.. say we have a MyClasss with namespace

namespace App\Doer;

class MyClass
{

    public static function just_do_it()
    {
        return 'I am doing it';

    }

}

On another page we can include the class page

include_once('location_of_the_class.php');

use App\Doer as Dude;

## call the static method
 print_r(Dude\MyClass::just_do_it());

Edited by veedeoo: more info added

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.