note 126308 added to function.function-exists

From: Date: Wed, 04 Aug 2021 02:46:04 +0000
Subject: note 126308 added to function.function-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-216739@lists.php.net to get a copy of this message
The confusion expressed in some of the submissions here arise because functions declared outside conditional blocks are defined as the code is loaded and are thus callable and exist wherever in the code they are declared, whereas those declared inside a condition block are not defined until that block is executed. Thus: echo foo(); function foo() { return "I am foo"; } yields : "I am foo" however because those inside a conditional are defined as they are encountered during code execution echo foo(); if(true) { function foo() { return "I am foo"; } } yields: Fatal error: Uncaught Error: Call to undefined function foo() ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 180.249.42.31) ---- Manual Page -- https://php.net/manual/en/function.function-exists.php Edit -- https://main.php.net/note/edit/126308 Del: integrated -- https://main.php.net/note/delete/126308/integrated Del: useless -- https://main.php.net/note/delete/126308/useless Del: bad code -- https://main.php.net/note/delete/126308/bad+code Del: spam -- https://main.php.net/note/delete/126308/spam Del: non-english -- https://main.php.net/note/delete/126308/non-english Del: in docs -- https://main.php.net/note/delete/126308/in+docs Del: other reasons-- https://main.php.net/note/delete/126308 Reject -- https://main.php.net/note/reject/126308 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216739) next »