Call to undefined method blitz::__construct()
Closed this issue · 9 comments
I do not know why, but I got this error:
Fatal error: Uncaught exception 'RuntimeException' with message 'Call to undefined method blitz::__construct()' in index.php
can't find my telepathic magic ball... won't you mind providing the code example so one can reproduce?
Hi,
I am sorry I was too fast to submit this issue without complete information.
I am trying to use zephir (http://zephir-lang.com) to make a PHP extension and use Blitz as template engine. Here is my code:
------ ZEPHIR CODE----
namespace test;
class testClass {
public function testBiltz(){
var T;
let T = new \Blitz("test.html");
T->display( ["name" : "John Doe"] );
}
}
------ ZEPHIR CODE----
After compiling the extension, PHP produced the above Fatal Error.
But, NO error was found when I tried to write in the PHP land like this:
display( array("name" =>"John Doe") ); } } ?>I guess it was zephir bug or the zephir way to standardize their code. But I posted issue here to get another insight from Blitz creator. My goal is to make fast application with PHP extension. I found Blitz is the best template engine to support it.
put just before your new Blitz line: var_dump(get_loaded_extensions()).
do you have blitz in this dump?
Yes, blitz is in the list (the last one).
array(59) { [0]=> string(4) "Core" [1]=> string(4) "date" [2]=> string(4) "ereg" [3]=> string(6) "libxml" [4]=> string(7) "openssl" [5]=> string(4) "pcre" [6]=> string(7) "sqlite3" [7]=> string(4) "zlib" [8]=> string(6) "bcmath" [9]=> string(3) "bz2" [10]=> string(8) "calendar" [11]=> string(5) "ctype" [12]=> string(4) "curl" [13]=> string(3) "dba" [14]=> string(3) "dom" [15]=> string(4) "hash" [16]=> string(8) "fileinfo" [17]=> string(6) "filter" [18]=> string(3) "ftp" [19]=> string(2) "gd" [20]=> string(7) "gettext" [21]=> string(3) "SPL" [22]=> string(5) "iconv" [23]=> string(4) "intl" [24]=> string(4) "json" [25]=> string(4) "ldap" [26]=> string(8) "mbstring" [27]=> string(7) "session" [28]=> string(8) "standard" [29]=> string(7) "mysqlnd" [30]=> string(4) "odbc" [31]=> string(6) "mysqli" [32]=> string(3) "PDO" [33]=> string(9) "pdo_mysql" [34]=> string(8) "PDO_ODBC" [35]=> string(10) "pdo_sqlite" [36]=> string(4) "Phar" [37]=> string(5) "posix" [38]=> string(10) "Reflection" [39]=> string(5) "mysql" [40]=> string(5) "shmop" [41]=> string(9) "SimpleXML" [42]=> string(4) "soap" [43]=> string(7) "sockets" [44]=> string(4) "exif" [45]=> string(7) "sysvmsg" [46]=> string(7) "sysvsem" [47]=> string(7) "sysvshm" [48]=> string(9) "tokenizer" [49]=> string(4) "wddx" [50]=> string(3) "xml" [51]=> string(9) "xmlreader" [52]=> string(6) "xmlrpc" [53]=> string(9) "xmlwriter" [54]=> string(3) "xsl" [55]=> string(3) "zip" [56]=> string(14) "apache2handler" [57]=> string(5) "pgsql" [58]=> string(5) "blitz" }
You need to dig into your code, at first your code just doesn't print anything, it just declares a class. I removed var/let as it seems to be useless here, fixed Blitz/Biltz and here's what's working:
Alexeys-MacBook-Pro:/blitz> php -v/blitz> cat test.php
PHP 5.5.12 (cli) (built: Sep 15 2014 13:06:52)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
Alexeys-MacBook-Pro:
Alexeys-MacBook-Pro:~/blitz> php test.php
Hello, John Doe
Can you run this?
First, thank you for your kind response.
I have no problem with PHP code. Blitz can run perfectly in the PHP land.
My problem is when I create blitz object in C (I want to create my own PHP extension).
I use zephir to produce C codes. And it always need to call blitz::__construct that seems not available.
Here the C code generated from zephir:
PHP_METHOD(MyExtension_Core, testBlitz) {
zval *_1;
int ZEPHIR_LAST_CALL_STATUS;
zval *view, *_0;
ZEPHIR_MM_GROW();
ZEPHIR_INIT_VAR(view);
object_init_ex(view, zephir_get_internal_ce(SS("blitz") TSRMLS_CC));
if (zephir_has_constructor(view TSRMLS_CC)) {
ZEPHIR_CALL_METHOD(NULL, view, "__construct", NULL, 0);
zephir_check_call_status();
}
ZEPHIR_INIT_VAR(_0);
ZVAL_STRING(_0, "Where is the {{ $what }}, Lebowski?", ZEPHIR_TEMP_PARAM_COPY);
ZEPHIR_CALL_METHOD(NULL, view, "load", NULL, 0, _0);
zephir_check_temp_parameter(_0);
zephir_check_call_status();
ZEPHIR_INIT_VAR(_1);
zephir_create_array(_1, 1, 0 TSRMLS_CC);
add_assoc_stringl_ex(_1, SS("what"), SL("John Doe"), 1);
ZEPHIR_CALL_METHOD(NULL, view, "display", NULL, 0, _1);
zephir_check_call_status();
ZEPHIR_MM_RESTORE();
}
Yes, now I got it. Can you help me and hack blitz.c then?
I think this can be resolved just by even __construct declaration in function_entry,
PHP_FALIAS(__construct, blitz_init, NULL)
just put this before
PHP_FALIAS(blitz, blitz_init, NULL)
UPDATE: please make sure it's blitz_init as I edited the comment
Wow thank you. It works.
I can not find "PHP_FALIAS(blitz, blitz_init, NULL)", so I add "BLITZ_ALIAS(__construct, blitz_init)" instead of "PHP_FALIAS(__construct, blitz_init, NULL)" on blitz.c line 5494
OK, so I was writing my comment based on my branch, while Tony changed that declaration in his arginfo patches. I added plain __construct declaration in 0.9.1 so this build should work for you with no changes.