- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Description
Description
Currently, when PHP functions have default arguments containing PHP code expressions (like __FILE__.$a), these expressions are stored as AST nodes and evaluated at runtime via the ZEND_RECV_INIT opcode. This approach has performance implications since it requires runtime evaluation of the AST for each function call where the default argument is used.
Current Behavior
function example($param = __FILE__ . '/suffix') {
// Function body
}
This currently generates a ZEND_RECV_INIT opcode that stores the expression __FILE__ . '/suffix' as an AST node for runtime evaluation.
Proposed Behavior
The same code would be compiled into bytecode operations, potentially like:
- Check if argument was provided
- If not, execute the compiled bytecode for the default value computation
- Jump to function body
Benefits
- Performance Improvement: Eliminates the overhead of storing and evaluating AST nodes at runtime
- Memory Optimization: Reduces memory usage by storing compiled bytecode instead of AST structures
- Execution Efficiency: Allows for potential compile-time optimizations of default value expressions
Technical Considerations
- The new opcode would need to handle both simple and complex expressions appropriately
- Special handling may be required for dynamic values like __FILE__
- Backward compatibility should be maintained for edge cases
Similar Precedents
This optimization approach is similar to how PHP already handles static variable initialization through:
- ZEND_BIND_STATIC
- ZEND_BIND_INIT_STATIC_OR_JMP