0

i am coding a PHP extension , i modify the zend_compile_file to my own function here is the source code :

FILE *bravery_ext_fopen(FILE *fp)
{
struct  stat    stat_buf;
char    *datap, *newdatap;
int datalen, newdatalen;
char sign[] = "BRAVERY";
int cryptkey_len = sizeof(sign);

fstat(_fileno(fp), &stat_buf);
datalen = stat_buf.st_size -  sizeof(sign);
datap = (char*)malloc(datalen);
fread(datap, datalen, 1, fp);
fclose(fp);

fp = tmpfile();

fwrite(datap, datalen-1, 1, fp);

free(datap);


rewind(fp);
return fp;
}
zend_op_array *bravery_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
FILE    *fp;
char sign[] = "BRAVERY";
char    buf[8];
char    fname[128];

memset(fname, 0, sizeof fname);
if (zend_is_executing(TSRMLS_C)) {
    if (get_active_function_name(TSRMLS_C)) {
        strncpy(fname, get_active_function_name(TSRMLS_C), sizeof fname - 2);
    }
}
if (fname[0]) {
    if ( strcasecmp(fname, "show_source") == 0
      || strcasecmp(fname, "highlight_file") == 0) {
        return NULL;
    }
}

fp = fopen(file_handle->filename, "r");
if (!fp) {
    return org_compile_file(file_handle, type TSRMLS_CC);
}

fread(buf, 7, 1, fp);
if (memcmp(buf, sign, 7) != 0) {
    fclose(fp);
    return org_compile_file(file_handle, type TSRMLS_CC);
}

if (file_handle->type == ZEND_HANDLE_FP) fclose(file_handle->handle.fp);
if (file_handle->type == ZEND_HANDLE_FD) close(file_handle->handle.fd);
file_handle->handle.fp = bravery_ext_fopen(fp);
file_handle->type = ZEND_HANDLE_FP;
//file_handle->opened_path = expand_filepath(file_handle->filename, NULL TSRMLS_CC);
file_handle->opened_path = NULL;
return org_compile_file(file_handle, type TSRMLS_CC);
}

its works good on normal PHP files, BUT it gives me a Fatal error: Unknown: Failed opening required 'C:\php5411\1.php' (include_path='.;C:\php\pear') in Unknown on line 0 error to me when the phpfile start with "BRAVERY"(this is what i am using to sign my php file).

here is the debug info of file_handle.Could any one help me? sorry for the google docs link cause i cannot post image here

img link

4

1 回答 1

0

这是 PHP 新手经常遇到的问题。我理解这种挫败感,因为当我是新手并且找不到答案时,这种情况发生在我身上。“require”语句要求您不要使用括号。如果您使用括号,它会将其视为逻辑语句。由于语句是 ("ThisIsAstring") 它被解释为 true 或 1(它不是一个空字符串)。删除括号。:D

编辑:作为说明,当您遇到这样的半模棱两可的错误时,您应该真正包含所有源代码。

这是在 stackoverflow 上找到的一个很好的答案:我什么时候应该在 require/include 语句中使用括号?

于 2013-07-04T02:04:19.087 回答