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
A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
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
C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
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
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
B.Closure — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
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
D.Closure — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
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
B.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
D.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
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"?
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
B.use binding — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
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
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
A.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
B.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
C.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
D.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
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
B.yield — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
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
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
A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
B.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
C.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
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
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"?
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
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
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
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
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
B.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
C.the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
D.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
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"?
A.Closure bindTo — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
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
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
D.Closure bindTo — an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
A.an anonymous function object that can capture variables from the scope in which it was defined for later use when invoked
B.an object that implements iteration by producing values one at a time on demand, avoiding building an entire collection in memory at once
C.the clause attached to an anonymous function that explicitly imports outer-scope variables, by value unless prefixed with an ampersand for a reference
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
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"?
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
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
C.Reference — the keyword that pauses a function and emits a value to the caller, turning that function into a lazily iterated generator
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
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.