0

Since I am struggling to find any official inforamtion about use() can soemone link me the PHP page of it?

$closure = function use($var) {
   //> Code    
}

As someone posted I of course already saw this link:

But it doensn't explain use at all (except for a little example)

Addendum

I do not want to discuss if use should or should not used

PS. I asked this because I think use is so much important for closures and it seems there isn't any official docs (except for the RFC link posted by OZ_)

  • I downvoted because it seems this question isn't really asking anything. Questions on Stack Exchange and all affiliated sites are meant to ask for information and answers. – Joseph Hansen May 26 '11 at 20:12
  • @joshm: Tanks for your explanation of downvote. I asked this because I think `use` is so much important for closures and it seems there isn't any official docs –  May 26 '11 at 20:14
  • -1 Why doesn't the manual document this? The last code example on your link shows an example and explains the behavior in the paragraph above it. It does leave out some details - like not being able to use $this in PHP < 5.4 - but it documents the basic behavior. – NikiC May 26 '11 at 20:27
  • @nikic: Maybe I can't read but in my link I can't find any explanation of USE execpt an example that can be suitable for a novice too –  May 26 '11 at 20:28
  • @yes: The paragraph above the example: "Closures may also inherit variables from the parent scope. Any such variables must be declared in the function header. [...]" – NikiC May 26 '11 at 20:29
  • @nikic: still 0 reference to `use` there –  May 26 '11 at 20:32

3 Answers3

0

In PHP 5.3.0, what is the function "use" identifier?

Community
  • 1
  • 1
Christopher Armstrong
  • 7,907
  • 2
  • 26
  • 28
  • Thanks for the link. But I would like see if there is an official docs for `use` in php.net because I consider it's pretty important for closurues and because it vaguely reminds me of some c++ syntax – dynamic May 26 '11 at 20:16
0

http://php.net/manual/en/functions.anonymous.php#example-154
https://wiki.php.net/rfc/closures

I can't understand which documentation are you looking for, it's very simple thing. use defines variables, which will be accessible for anonymous function. Variables in use assigned when they are defined, not when function will be called, and it gives the power :)

OZ_
  • 12,492
  • 7
  • 50
  • 68
  • 2
    Except for a little example that is completly without exaplanation – dynamic May 26 '11 at 20:08
  • See second link. I'm sure you can use google for such primitive questions. – OZ_ May 26 '11 at 20:10
  • your second link is much better but still I asked for an official php.net documentation. And of course I searched on google before asking this question in fact until now you didn't replied me – dynamic May 26 '11 at 20:11
  • @yes123 both these links are to php.net – OZ_ May 26 '11 at 20:13
  • @yes123 see the link I posted - it's another question here on SO with a great discussion about closures. – Christopher Armstrong May 26 '11 at 20:14
  • @OZ: yes, obviously he should google it. "use" is such a unique keyword that Google will immediately bring the matching result. After all, it's not like "use" could have any other meaning, right? Why post such primitive questions? Can't the original poster guess the meaning of keywords not explicitly defined in the official documentation? When the clearest explanation of a keyword comes from a proposal in an RFC (which does not show when you search Google for "function use php"), there is something missing in the documentation. – Sylverdrag May 29 '11 at 02:13
  • @Sylverdrag, I found this links in Google. Try `php closures`. – OZ_ May 29 '11 at 05:22
  • @OZ: Knowing what to look for exactly is the trick, isn't it? Especially with common words like "use". If you know that "use" only applies to closures, searching for closures is natural. But if you only know that you don't understand the keyword "use", the logical thing to do is search for "use", and the signal/noise ratio is too low. Most questions on SO have already an answer somewhere on the net. If we start dismissing questions on that basis, there won't be much left. And as for "primitive questions", come on, closures are not exactly "PHP 101". – Sylverdrag May 29 '11 at 11:11
0

Except for the little example here http://php.net/manual/en/functions.anonymous.php and wiki page here https://wiki.php.net/rfc/closures

the answer is no: there isn't any official documentation about use.

dynamic
  • 46,985
  • 55
  • 154
  • 231