--- id: php-callback-functions title: "PHP Callback Functions" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["anonymous function callback", "PHP 콜백 ν•¨μˆ˜"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "callback", "functions"] raw_sources: ["https://www.w3schools.com/php/php_callback_functions.asp"] applied_in: [] github_commit: "" --- # [[PHP Callback Functions]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) A named function used as a callback is passed as a plain STRING ("myfunction"), not as a special function-reference syntax β€” meaning any existing function automatically qualifies as a callback with zero extra syntax, while anonymous functions are defined inline specifically for one-off, unnamed use cases. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Callback function** β€” a function passed as an argument into another function. [S1] - **Named function callback** β€” pass the function's name as a string: `array_map("myfunction", $numbers)`. [S1] - **Anonymous function callback** β€” defined inline: `array_map(function($n) {return($n * $n);}, $numbers)`. [S1] - **Callbacks in user-defined functions** β€” a parameter holding a function is invoked by adding parentheses: `$format($str)`. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) - Named function as callback: `function myfunction($n) { return($n * $n); } $numbers = [1, 2, 3, 4, 5]; print_r(array_map("myfunction", $numbers));`. [S1] - Anonymous function as callback: `$res = array_map(function($n) {return($n * $n);}, $numbers);`. [S1] - Callback passed to a user-defined function: `function printFormatted($str, $format) { echo $format($str); } printFormatted("Hello world", "exclaim"); printFormatted("Hello world", "ask");` (where `exclaim` and `ask` are separately-defined named functions). [S1] ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) μ†ŒμŠ€μ—μ„œ λͺ¨μˆœλ˜λŠ” μ •λ³΄λŠ” λ°œκ²¬λ˜μ§€ μ•ŠμŒ. ## πŸ› οΈ 적용 사둀 (Applied in summary) ν˜„μž¬ 발견된 μ‹€μ œ 적용 사둀가 μ—†μŠ΅λ‹ˆλ‹€ β€” array_map()에 μ½œλ°±μ„ 전달해 λ°°μ—΄μ˜ λͺ¨λ“  μš”μ†Œλ₯Ό λ³€ν™˜ν•˜λŠ” 것이 ν•¨μˆ˜ν˜• μŠ€νƒ€μΌ λ°°μ—΄ 처리의 λŒ€ν‘œ 사둀닀. [S1] ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) User-defined function accepting a callback (PHP): ```php function exclaim($str) { return $str . "! "; } function printFormatted($str, $format) { echo $format($str); } printFormatted("Hello world", "exclaim"); ``` ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[PHP Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[PHP Filter Advanced]], [[PHP JSON]], [[PHP Arrays Functions]] - **μ°Έμ‘° λ§₯락:** ν•¨μˆ˜λ₯Ό 인자둜 μ „λ‹¬ν•˜λŠ” νŒ¨ν„΄ β€” JSON μ±•ν„°λ‘œ 이어짐. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” PHP Callback Functions β€” https://www.w3schools.com/php/php_callback_functions.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Callback Functions" page (Astra wiki-curation, P-Reinforce v3.1 format).