开发者

Combining 2 PHP frameworks that both implement __() internationalization function

开发者 https://www.devze.com 2023-02-01 07:33 出处:网络
Never had a question I couldn\'t google until now, and it may be a doozy: I have a PHP site that combines Wordpress with Kohana - Wordpress for the blog, and Kohana for the custom functionality. This

Never had a question I couldn't google until now, and it may be a doozy:

I have a PHP site that combines Wordpress with Kohana - Wordpress for the blog, and Kohana for the custom functionality. This is done using a Wordpress plugin that stitches them together.

This works great except they both define a __() internationalization function, with different arguments etc. so once wordpress has overridden kohana's __(), if kohana calls __() it explodes.

I'm not that familiar with PHP so this might be naive, but shouldn't this stuff be namespaced? Is there anyway other than changing the source of one or the other framework to a开发者_如何转开发llow them to call their own respective __()?


I've done some work integrating Wordpress with Kohana. See this post. It's easier to rename and replace __() in Kohana than it is to do so for Wordpress, trust me.


Namespaces are new in PHP 5.3. Almost all existing software projects don't use them, since they want to be compatible with older versions of PHP. Many (most?) aren't even object oriented! You could replace every instance of __ with another valid (and unique!) function name in one of the projects, but that will make updating that project difficult even though it's probably the best solution.


Using namespaces may be a tedious task as it may require you a lot of code change. I would suggest replacing the __() function in Wordpress with some other name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号