가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Chapter 7

Advanced Functions, Scope, References, Closures, and Callback Thinking

Move beyond simple functions and learn how PHP handles variable scope, anonymous functions, and reusable callback patterns.

Inside this chapter

  1. Variable Scope
  2. Pass by Value and Reference
  3. Anonymous Functions and Closures
  4. Array Callback Patterns
  5. Where This Matters

Series navigation

Study the chapters in order for the clearest path from PHP basics to backend architecture, security, deployment, and production engineering habits. Use the navigation at the bottom to move smoothly through the full tutorial series.

Tutorial Home

Chapter 7

Variable Scope

Variables inside a function are local by default. PHP also supports global variables, but strong code usually prefers passing values clearly rather than depending heavily on global state.

$taxRate = 0.1;

function showValue() {
    $local = "inside";
}
Chapter 7

Pass by Value and Reference

function addBonus(&$score) {
    $score += 5;
}

PHP can pass variables by reference when needed, but this should be used carefully because it makes data flow less explicit.

Chapter 7

Anonymous Functions and Closures

$greet = function ($name) {
    return "Hello, " . $name;
};

Closures are useful for callbacks, array transformations, middleware-like logic, and modern framework code. They are part of everyday PHP once projects become more advanced.

Chapter 7

Array Callback Patterns

$numbers = array(1, 2, 3);
$doubled = array_map(function ($n) {
    return $n * 2;
}, $numbers);

Callbacks help transform, filter, or sort data in clean reusable ways.

Chapter 7

Where This Matters

In modern PHP frameworks and libraries, closures appear in routes, collections, validation rules, middleware, event handlers, and service configuration. Students should become comfortable reading and writing them.

Copyright © 2026, WithoutBook.