VarDump() function

Propose new features and changes
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

VarDump() function

07 Apr 2018, 16:35

Do we have a function to dump (print) entire variable, including arrays and objects?

Normally one can MsgBox(variable), as long it's simple type - such as string, integer, and so on (or rather transformed to string for displaying). It's not as simple for arrays and objects though, so I think we could use a dedicated function. Consider PHP's var_dump as example.

Cap'n Odin wrote the following on-the-go, but it's far from what it can become:

Code: Select all

ObjToString(obj)
{
	if (!IsObject(obj))
		return obj
	str := "`n{"
	for key, value in obj
		str .= "`n" key ": " ObjToString(value) ","
	return str "`n}"
}
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: VarDump() function

07 Apr 2018, 17:22

There is a related thread here.
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: VarDump() function

07 Apr 2018, 17:47

wolf_II wrote:There is a related thread here.
That's basically this: https://autohotkey.com/boards/viewtopic ... 37&t=39309

JSON (as in string form) is usually minified by removing all unnecessary white symbols (new lines, tabs, spaces). Not only it lacks formatting, but also does not provide extra information (variable type and length).
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: VarDump() function

07 Apr 2018, 17:56

OK, I see. Thx. For further clarification, can't you put in a JSON or any other general type of associated object any data you want?
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: VarDump() function

08 Apr 2018, 04:47

Quick comparison - dumped object vs JSON:

Code: Select all

$obj = new DateTime();
var_dump($obj);
object(DateTime)#1 (3) {
["date"]=>
string(26) "2018-04-08 08:42:05.700165"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}

Code: Select all

// ...
$json = json_encode($obj);
var_dump($json);
echo($json);
string(72) "{"date":"2018-04-08 08:42:05.700165","timezone_type":3,"timezone":"UTC"}"
{"date":"2018-04-08 08:42:05.700165","timezone_type":3,"timezone":"UTC"}
JSON is basically stringified array, that is meant to be parsed / transferred into equivalent structure in the environment it's loaded in. Think of it as universal way of passing variables from one program to another, even throughout the Internet. Something like XML.
While the parser can tell timezone_type is an integer, because there are no quotes between 3, it can't tell that the parent was a DateTime object.

While I do want JSON to be inbuilt (as a replacement for ini and further usage), this is simply something else than I spoke of in this topic.
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: VarDump() function

13 Apr 2018, 01:27

Hello, maybe this will interest you: [Lib] ObjDump / ObjLoad - Object Backup by HotKeyIt.

Cheers.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 77 guests