If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

No. But the information can be gotten. It depends upon the type of object the variable refers to. A blanket function could be made to test that, with at least one caveat. It also depends upon how you want to see the result.

It would be easier to tell you how to get it for one type of object, where you already know the type. For an array:

print_r() works for associative arrays in PHP, and basically considers numbered indices as associative keys of that number. I'm not sure if Javascript handles it differently, but what you've done in the first couple posts should cover it.
What you just wrote, John, is more like the var_dump() function in PHP that prints all the information contained in any variable, be it an object, array, whatever.

What I've done is (as far as it goes, like I say - not perfect) almost exactly like PHP's print_r(), which does both associative arrays and those without keys, as well as objects, strings and numbers. It also does booleans - sort of - undocumented, 1 for true, an empty string for false. All I've really added are functions and a sort of catch all to at least try to give a type if javascript can't break down whatever is fed to this function using the function's methods. I only did those because javascript fairly easily can. I don't think PHP does functions at all in that manner. But I'm still just learning PHP, so I wouldn't want to make a negative claim. I can make a positive claim though as I have here about PHP's print_r() because it's all pretty much right there in the manual.

Note: There are no associative arrays in javascript. Well there are, but they're called and technically are objects and use the object syntax, so are constructed with the Object constructor.

As far as I know, the exception is objects. I didn't mean that as a complaint, but just that you'd done a little more than is needed (at least if print_r() really is the goal). var_dump() which handles any type of variable is more useful (in general).

If given a string, integer or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.

So it does objects (or claims to), and so does the javascript version. I think I have had some experience with PHP's print_r() where it didn't yield much useful information about a particular object. I believe that was because the object itself contained at least one nested object. In the javascript version that too will frustrate your efforts unless the javascript print_r() function is edited to recognize such a situation and deal with it, similar to walking down all descendant nodes in a DOM tree until there are no more child nodes.

I'm not sure how or if it's even possible to do that in PHP, though it probably is.

One thing I'm perhaps the least clear on with this concept in PHP is functions. I mean, it appears that you cannot do:

PHP Code:

$myFunc = function(){return whatever;};

And that doing:

PHP Code:

function someFunc(){whatever;}

doesn't seem to make someFunc into something that can be printed. It can be referenced and used in its scope, just not printed out. But I would want to do further testing on that before saying so definitively.