سؤال

I'm doing some experiments with Phalcon Zephir to see how well it can convert some of my libraries to PHP extensions.

I have two PHP classes, each already defined in its own file: the Zephir notes are quite clear that this must be the case.

trienode.zep

namespace tries;

class trienode
{
    public children;

    public valueNode = false;

    public value = null;

    public function __construct()
    {
        let this->children = [];
    }
}

and

trie.zep

namespace tries;

class trie {

    private trie;

    public function __construct() {
        let this->trie = new trienode();
    }
}

But whenever I try to compile the classes using zephir compile, I get

Warning: Class "trienode" does not exist at compile time  in /home/vagrant/ext/tries/tries/trie.zep on 8 [nonexistent-class]

            let this->trie = new trienode();
    ---------------------------------------^

(and if I continue through the build process, and install the resultant .so file, it errors when I try to use it from within a PHP script)

<?php

namespace tries;

$test = new trie;

giving

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20121212/tries.so' - /usr/lib/php5/20121212/tries.so: undefined symbol: zephir_tries_trie_init in Unknown on line 0
PHP Fatal error:  Class 'tries\trie' not found in /home/vagrant/triesTest.php on line 5

I've looked through the Zephir documentation, and various blog posts, but can't find any examples of building an extension that comprises more than a single class file.

Has anybody succeeded in building an extension using Zephir that does comprise more than a single class? And if so, what settings or configuration options (or additional steps) does it require to build a working so?

هل كانت مفيدة؟

المحلول

It looks like the namespace has to be included in the call.

let this->trie = new tries\trienode();
//                   ^^^^^^

I didn't see this explicitly mentioned in the documentation, but is hinted at (pardon the pun) in the Return Type Hints section, which uses the namespace in the hints.

Changing your example class to that shown above allows the extension to compile as desired.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top