Skip to content

Php::eval function behaviour change after >PHP8.2 versions #540

@dogukanoksuz

Description

@dogukanoksuz

Before PHP8.2, Php::eval function evaluated code without requirement of <?php starter tag.
After PHP8.2 (PHP8.3, PHP8.4) it does not work as expected.

return zend_compile_string(zval_get_string(source._val), (char*)name, ZEND_COMPILE_POSITION_AT_OPEN_TAG);

Here is the mentioned line, is there anything i can do for retrieving old behaviour?

Example code:

#include <phpcpp.h>
#include <iostream>
#include <string>

/**
 * Simple function that demonstrates Php::eval
 */
Php::Value eval_test(Php::Parameters &params)
{
    // Execute PHP code using Php::eval
    Php::Value result = Php::eval("return 'test';");
    
    // It returns test before PHP8.3
    // It returns just string like; "return 'test';" after PHP8.3
    // To get it working we should use it like:
    Php::Value result = Php::eval("<?php return 'test';");
    // But it breaks backwards compability for my case
    
    // Return the result
    return result;
}

/**
 * Extension initialization
 */
extern "C" {
    PHPCPP_EXPORT void *get_module()
    {
        // Create extension
        static Php::Extension extension("eval_test", "1.0");
        
        // Add the eval_test function
        extension.add<eval_test>("eval_test");
        
        // Return the extension
        return extension;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions