Closures & Generators interview questions

18 real Closures & Generators questions from the PHP bank, as asked in Indian campus drives and tech interviews. Every question has a verified answer and an AI-tutor explanation on placd — free to start.

1. What is Closure?

Junior
  1. A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  2. B.an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
  3. C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  4. D.the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to
Reveal the answer + AI explanation — free account

3. Which statement is correct?

Junior
  1. A.Closure — the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  2. B.Closure — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  3. C.Closure — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  4. D.Closure — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
Reveal the answer + AI explanation — free account

4. What is use binding?

Mid
  1. A.an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
  2. B.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  3. C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  4. D.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
Reveal the answer + AI explanation — free account

5. Which term means: "the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference"?

Mid
  1. A.use binding
  2. B.yield
  3. C.Closure bindTo
  4. D.Generator
Reveal the answer + AI explanation — free account

6. Which statement is correct?

Mid
  1. A.use binding — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  2. B.use binding — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  3. C.use binding — an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
  4. D.use binding — the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
Reveal the answer + AI explanation — free account

7. What is yield?

Mid
  1. A.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  2. B.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  3. C.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  4. D.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
Reveal the answer + AI explanation — free account

9. Which statement is correct?

Mid
  1. A.yield — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  2. B.yield — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  3. C.yield — the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  4. D.yield — the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to
Reveal the answer + AI explanation — free account

10. What is Generator?

Mid
  1. A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  2. B.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  3. C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  4. D.an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
Reveal the answer + AI explanation — free account

11. Which term means: "an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once"?

Mid
  1. A.Closure
  2. B.Closure bindTo
  3. C.Generator
  4. D.Reference
Reveal the answer + AI explanation — free account

12. Which statement is correct?

Mid
  1. A.Generator — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  2. B.Generator — the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  3. C.Generator — an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
  4. D.Generator — the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to
Reveal the answer + AI explanation — free account

13. What is Closure bindTo?

Senior
  1. A.the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to
  2. B.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  3. C.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  4. D.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
Reveal the answer + AI explanation — free account

14. Which term means: "the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to"?

Senior
  1. A.use binding
  2. B.Closure bindTo
  3. C.Reference
  4. D.yield
Reveal the answer + AI explanation — free account

15. Which statement is correct?

Senior
  1. A.Closure bindTo — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  2. B.Closure bindTo — the method that returns a copy of an anonymous function rebound to a new object and class scope, redefining what the this pseudo-variable resolves to
  3. C.Closure bindTo — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  4. D.Closure bindTo — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
Reveal the answer + AI explanation — free account

16. What is Reference?

Senior
  1. A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
  2. B.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  3. C.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
  4. D.an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
Reveal the answer + AI explanation — free account

17. Which term means: "an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other"?

Senior
  1. A.yield
  2. B.Closure bindTo
  3. C.Reference
  4. D.use binding
Reveal the answer + AI explanation — free account

18. Which statement is correct?

Senior
  1. A.Reference — an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
  2. B.Reference — an alias created with an ampersand so two variable names point to the same underlying storage, where assigning through one changes the value seen by the other
  3. C.Reference — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
  4. D.Reference — the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
Reveal the answer + AI explanation — free account

Free to start

Answers, AI explanations, and a scored voice mock interview

Sign up free to check your answers with explanations, ask the AI tutor anything on any question, and take one full AI mock interview — scored like a real panel.

Practice Closures & Generators free