【发布时间】:2015-10-24 12:04:07
【问题描述】:
我有 2 个类,每个类都有 2 个方法。此外,我在所有类的所有方法之间都有一些常量数据。
所以我使用了一个包含这些常量数据的父类,然后我扩展了父类的其他类(用于访问所有类的所有方法中的常量数据)。
这是我的结构:github demo
// c:\xampp\htdocs\myweb\classes
// ---------------------------------------------------- Father.php
class Father{
protected $arr1 = array("there is some data in here");
protected $arr2 = array("there is some data in here");
protected $arr3 = array("there is some data in here");
}
// ---------------------------------------------------- Autoloader.php
function my_autoloader($class) {
require_once($class.".php");
}
spl_autoload_register('my_autoloader');
// ---------------------------------------------------- Child1.php
class Child1 extends Father{
public function func1(){// using of those array in this method}
public function func2(){// using of those array in this method}
}
// ---------------------------------------------------- Child2.php
class Child2 extends Father{
public function func1(){// using of those array in this method}
public function func2(){// using of those array in this method}
}
现在我想知道,如何使用 composer autoloader 实现我的代码?
【问题讨论】:
-
你想要psr-0/4的文档吗?
-
@Federico 我想使用作曲家。
-
我不明白,你要使用composer的自动加载器吗?还是什么?
-
@Federico 是的,我想使用 composer 的自动加载器
标签: php oop composer-php autoloader