Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About PHP 5.5 Trait #75

Open
lilj opened this issue Nov 29, 2013 · 7 comments
Open

About PHP 5.5 Trait #75

lilj opened this issue Nov 29, 2013 · 7 comments

Comments

@lilj
Copy link

lilj commented Nov 29, 2013

鸟哥. 好.

我想在PHP5.5下使用 Trait, Yaf 能自动载入 包含Trait 的文件么? 就像 Model,或者 Lib 一样?
如果能, 请问怎么设置

如果不能, 请问是否会增加这样特性?

谢谢.

@zxcvdavid
Copy link
Contributor

加载和 Trait没关系..只要你的加载规则没问题就行..

@lilj
Copy link
Author

lilj commented Nov 29, 2013

我是想把Trait按规则放到单独的文件里面. 不用include 神马的, 直接就可以use了.
现在的 lib 不正是这样的么?

@lilj
Copy link
Author

lilj commented Nov 29, 2013

可以了, 没有registerLocalNameSpace ...
找到一点资料.
http://stackoverflow.com/questions/10641824/php5-4-autoloading-traits

Sorry, 没仔细研究就发问了.

@lilj lilj closed this as completed Nov 29, 2013
@wenjun1055
Copy link
Contributor

这个问题很好,哈哈

@lilj
Copy link
Author

lilj commented Jun 7, 2020

好多年过去了, 鸟哥最近频繁出没, 重新提一下这个需求,这样就能不用spl_autoload了。

<?php

spl_autoload_register(function($traitName) {
	$fileName = APP_PATH.'traits/' . $traitName . '.php';
	if (file_exists($fileName)) {
		include_once $fileName;
	}
});

final class Test_Controller extends Yaf_Controller{
	use Mds;
	...
	
}

@lilj lilj reopened this Jun 7, 2020
@laruence
Copy link
Owner

laruence commented Jun 8, 2020

你可以通过registerNamespace(“类名前缀”, “路径“)来加载啊

@laruence
Copy link
Owner

laruence commented Jun 8, 2020

3.2版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants