Jump to content

Get array with local vars only


sen5241b
 Share

Go to solution Solved by benanamen,

Recommended Posts

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 by ginerjm
Link to comment
Share on other sites

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 by sen5241b
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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 by benanamen
Link to comment
Share on other sites

  • 2 weeks later...
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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.