scope - Why can't I access the variables set in a php file -


i have 2 php files,

action.php

require_once 'action_helper.php';  storedatatodb($data); //function action_helper.php logpersistisperformed(); //function action_helper echo $success; //variable set in action_helper.php 

action_helper.php

$success = "success";   function storedatatodb($data) {     // persist data }  function logpersistisperformed() {     inserttodb($success); } 

i'm not sure if scope issue encounter when action.php calls functions , variables declared in action_helper.php there no issues.

but when call function in action_helper.php action.php, calls variable declared in action_helper.php, doesn't seem see success variable.

during debugging, once loaded page, see variables both action , action_helper. when step function action_helper, i'm not able see variables declared in action_helper variables passed function.

you need use global keyword let php know $success global variable.

function logpersistisperformed() {     global $success;     inserttodb($success); } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

python 3.5 - Pyqtgraph string in x tick -