sen5241b Posted January 12, 2023 Share Posted January 12, 2023 Tried $LocalAndGlobalVars = get_defined_vars(); $LocalVarsOnly = return array_diff_key($LocalAndGlobalVars, $GLOBALS); var_dump($LocalVarsOnly); no dice. Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/ Share on other sites More sharing options...
requinix Posted January 12, 2023 Share Posted January 12, 2023 Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604571 Share on other sites More sharing options...
ginerjm Posted January 12, 2023 Share Posted January 12, 2023 (edited) If you had error checking turned on you would see that the return is not supposed to be there. Plus I don't see any local vars being defined in your 'script' And just what are you trying to find? Edited January 12, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604572 Share on other sites More sharing options...
sen5241b Posted January 13, 2023 Author Share Posted January 13, 2023 (edited) sorrry my previous code was not enough PSEUDO CODE: get all vars noth local and global get them all again right before you need an array of local vars compare 2 arrays -- what vars are new?pseudo logic: An easier way? <?php /* get all vars local and global get them all a 2nd time -- compare 2 arrays -- what vars are new? */ error_reporting(E_ALL); ini_set('display_errors', '1'); $varY = 4433449; // should NOT diplay s local var $InitialGLOBALS = get_defined_vars(); unset($InitialGLOBALS['GLOBALS']); // unsetting these avoids recursion, true? unset($InitialGLOBALS['_GET']); // these too? unset($InitialGLOBALS['_POST']); unset($InitialGLOBALS['_FILES']); unset($InitialGLOBALS['_COOKIE']); $ALocalVar = 'WASSUP!'; DefineVars(); $LocalAndGlobalVars = get_defined_vars(); unset($LocalAndGlobalVars['GLOBALS']); // avoids recursion unset($LocalAndGlobalVars['_GET']); unset($LocalAndGlobalVars['_POST']); unset($LocalAndGlobalVars['_FILES']); unset($LocalAndGlobalVars['_COOKIE']); unset($LocalAndGlobalVars['InitialGLOBALS']); $LocalVars = array_diff_key($LocalAndGlobalVars, $InitialGLOBALS); echo '<br>'; echo '<br> local vars='; echo '<br>'; print_r($LocalVars); echo '<br>'; exit('fin'); function DefineVars() { $NotALocalVar = 5569.6666234; // should never display } ?> Edited January 13, 2023 by sen5241b Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604579 Share on other sites More sharing options...
benanamen Posted January 13, 2023 Share Posted January 13, 2023 What is the problem you are trying to solve by doing this? Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604580 Share on other sites More sharing options...
ginerjm Posted January 13, 2023 Share Posted January 13, 2023 Same question I asked since I never even knew these functions were out there and had no needs of this kind. OP - your original code was almost perfect. That 'return' was causing an error for you and the fact that you had no locals defined gave you an unexpected empty answer. Your new solution is really unnecessary. Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604581 Share on other sites More sharing options...
sen5241b Posted January 13, 2023 Author Share Posted January 13, 2023 The problem? I'm writing a lightweight data agnostic processing engine (engine doesn't care what kind of data its proccessing). It enables user to get items from a data catalog and add to it by simply adding new catalog items. I want to pass local vars from the agnostic engine controller to the engine processor which sort of goes against the whole concept. Its a work in progess.. Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604588 Share on other sites More sharing options...
ginerjm Posted January 13, 2023 Share Posted January 13, 2023 So you want to see those vars that are 'local' which means they are not global. I, for one, have no idea why anyone would be writing code like this. But I can tell you that local vars are those that are limited in scope which mean they are probably in a user-written function and your use of these functions must happen inside of that function. And that is all I have to say. Bye. Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604594 Share on other sites More sharing options...
Solution benanamen Posted January 13, 2023 Solution Share Posted January 13, 2023 (edited) I am still not sure what you are doing with out more details, but I am sure that whatever you are attempting to do with the posted code is not the way to do it. 5 hours ago, sen5241b said: I'm writing a lightweight data agnostic processing engine This should be to focus of your post. 5 hours ago, sen5241b said: It enables user to get items from a data catalog and add to it by simply adding new catalog items. More details or some third party example is in order at this point. This just sounds like basic database management. Edited January 13, 2023 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1604601 Share on other sites More sharing options...
sen5241b Posted January 25, 2023 Author Share Posted January 25, 2023 On 1/13/2023 at 1:44 PM, benanamen said: I am still not sure what you are doing with out more details, but I am sure that whatever you are attempting to do with the posted code is not the way to do it. This should be to focus of your post. More details or some third party example is in order at this point. This just sounds like basic database management. Yes the engine should’ve been the Focus on the post. There is nothing new about the idea of a data agnostic processing engine that takes only metadata and a few snippets of code to produce the same output that a dedicated app would otherwise produce. ServiceNow has a feature called Workflows, that requires only data definitions and a few snippets of code to produce the same output that a dedicated App would produce. Quote Link to comment https://forums.phpfreaks.com/topic/315793-get-array-with-local-vars-only/#findComment-1605005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.