Skip to content

Conversation

@arnaud-lb
Copy link
Owner

@arnaud-lb arnaud-lb commented Oct 16, 2025

RFC: https://wiki.php.net/rfc/context-managers

This implements with() / context managers mostly as syntax sugar.

One opcode is added as it reduces the generated code size considerably. This avoids generating code for:

if (!$__mgr instanceof ContextManager) {
    $type_name = is_object($__mgr) ? get_class($__mgr) : gettype($__mgr);
    $message = "with() expression must be of type ContextManager, $type_name given";
    throw new TypeError($message);
}

TODO:

  • resource support
  • non-var on the rhs of as

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant