# RFC: Allow use T_AS in closure use statement

- Status: Withdrawn
- Authors: Xinchen Hui laruence@php.net
- Date: 2012/04/12
- Version: 1.0
- Original: https://wiki.php.net/rfc/useas
- Page: https://externals.io/rfc/useas
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Discussions on the mailing list

- [\[RFC\] Allow "use( $longname as $alias)" syntax for closures declaration](https://externals.io/message/59791.md) — started on 2012-04-12, 13 messages
- [Call for voting: \[RFC\] Allow use T_AS in closure use statement](https://externals.io/message/61404.md) — started on 2012-07-18, 14 messages

---

## Introduction

Allow use AS in the closure declaration, like:

```
<?php
  $foo = "bar";
  
  $func = function () use ($foo as $dup, &$foo as $ref) { //alias name
  };
  
```

## Proposal

I have made a patch, after patch, the following script:

```
<?php

$a = "2";

$b = function() use (&$a as $b, $a as $c, $a as $e) {
    echo $b;
    echo $c;
    echo $e;
    $b = 4;
};

$b();

echo $a;

class Foo {
    public function closure() {
        return function () use ($this as $obj) {
            var_dump($obj);
        };
    }
}

$foo = new Foo();

$a = $foo->closure();
$a();
```

will output:

```
2224object(Foo)#2 (0) {
}
```

I will be keeping improve this patch.

## Patch

- <https://gist.github.com/2367913>

## Changelog

- 2012-04-12 Xinchen Hui Initial version
- 2012-07-18 Xinchen Hui Open voting
- 2012-07-19 Xinchen Hui Draw back, add dynamic variable supporting
