我正在尝试编辑 PHPWord 插件以更好地满足我的需求。通过制作 PHPWord 主类包含的部分列表,我可以将部分插入到文档中的任何顺序中,而不仅仅是一个我无法重新排序的固定列表。
但是我收到一个错误消息syntax error, unexpected 'new'
,这让我发疯了。
还有其他人知道更多关于这个 PHPWord 工具的信息吗?我没有从他们的 Github 问题跟踪器/论坛得到答案。
他们有他们定义的工具使用的类,我需要以某种方式将其添加为资源?由于某种原因,我不能只是添加它。
非常感谢!
编辑:
我尝试在此行上创建一个新对象,而不是 array() 或 SplDoublyLinkedList(),无论我尝试分配插件范围之外的其他对象,我都会收到“新”语法错误。
我也试过new ArrayObject();
了,但我仍然收到错误。
PHPWord 使用Autoloader
? 这是他们的自动加载器代码,我是否需要以某种方式包含我想在这里使用的任何额外类?
namespace PhpOffice\PhpWord;
/**
* Autoloader
*/
class Autoloader
{
/** @const string */
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
/**
* Register
*
* @param bool $throw
* @param bool $prepend
* @return void
*/
public static function register($throw = true, $prepend = false)
{
spl_autoload_register(array(new self, 'autoload'), $throw, $prepend);
}
/**
* Autoload
*
* @param string $class
* @return void
*/
public static function autoload($class)
{
$prefixLength = strlen(self::NAMESPACE_PREFIX);
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (file_exists($file)) {
/** @noinspection PhpIncludeInspection Dynamic includes */
require_once $file;
}
}
}
}