0

In my project, I want call a function xieTest() in Datasource class.

The content of Datasource class is :

namespace common;

class Datasource 
{

    public function __construct() 
    {

    }

    public static function xieTest()
    {
        $str = "xietest";
        return $str;
    }
}

And my html test.php code is :

<body style="height:100%" >
<?php 

$redis_obj = o1ws1v/class/common/Datasource::xieTest();

echo $redis_obj;

?>

</body>

My directory structure is:

/yjdata/www/www/test.php
/yjdata/www/www/o1ws1v/class/common/Datasource

It works fail, It seems nothing wrong.

Who can help me?

Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55
stack
  • 821
  • 1
  • 15
  • 28
  • So what does your http servers error log file say? – arkascha Jun 09 '18 at 13:00
  • 4
    The bit before a class name is for the namespace, not a directory name. So either learn about autoloaders or include the file with the class in and reference it as `common\Datasource` – Nigel Ren Jun 09 '18 at 13:00
  • try thid **common/Datasource::xieTest();** – Davit Zeynalyan Jun 09 '18 at 13:05
  • @Davit, I use $redis_obj = common\Datasource::xieTest(); But it works fail – stack Jun 09 '18 at 13:13
  • @Davit That's basically what NigelRen suggested, only wrong. It's \, not /. – brombeer Jun 09 '18 at 13:14
  • @stack Did you "autoload" or "include" your Datasource file? – brombeer Jun 09 '18 at 13:16
  • @kerbholz, I use \ instead of /, But it also wrong. Both $redis_obj = common\Datasource::xieTest(); and $redis_obj = o1ws1v\class\common\Datasource::xieTest(); are wrong – stack Jun 09 '18 at 13:17
  • @stack Not quite. `$redis_obj = common\Datasource::xieTest();` is the correct way to go *IF* you included your Datasource file beforehand – brombeer Jun 09 '18 at 13:21
  • @kerbholz, yes, I added " include "o1ws1v/class/common/Datasource.php"; before $redis_obj = common\Datasource::xieTest(); it works Ok – stack Jun 09 '18 at 13:26

0 Answers0