Tinkerwell 4 is out now! See what's new or buy now.
Tinkerwell background image
Tinkerwell Logo Tinkerwell

Magic Comments
#

Magic Comments allow you to inspect the content of variables during runtime – like a complex debugging solution. They are a unique feature of Tinkerwell and they aren’t available in any other code runner in this form.

You can use them to display the state of variables and objects during the code execution. This is useful for debugging scripts, simplify coding challenges or you can use them permanently within Tinkerwell Snippets.

//?
#

The //? at the end of a line returns the value of this line. This is easier to understand when looking at the next screenshot.

$result = 1+1; //?
$result += 1; //?
$result += 1; //?

Tinkerwell prints out the result of each line and ends with the normal output within the output panel.

/*?->*/

While the //? comment comes very handy, the /?->/ is the real deal. It allows your to run methods or access properties while your code runs without changing the output of the overall script.

The following snippets uses the count() method of Laravel Eloquent to count the number of Tinkerwell users and adds a second query for the number of active users – the ones who validated their Tinkerwell license within the last 30 days.

AppLicense::where('app_id', 1)
/*?->count()*/ // Total Tinkerwell Users:
->where('last_validated_at', '>', now()->subDays(30))
/*?->count()*/; // Active Users in the last 30 days:

As you can see, there is a core group of developers who use Tinkerwell very regularly. These are usually the ones who learned how to use the app with all its benefits and stick with it for a long time.

Sometimes, it’s helpful to understand what your code does while it runs. This is helpful if you work with complex queries or collections and want to understand how filters and other methods work on your data.

The following example fetches a list of public repositories from GitHub, filters for all repositories that are Laravel related and maps them to their name only. During the code execution, Tinkerwell displays the number of all repositories, the number of filtered repositories and even all repository names while the filter runs.

Simply copy the code to the default app of your Tinkerwell app and play around with the GitHub API to learn how to use Magic Comments in Tinkerwell.

collect(
Http::get('https://api.github.com/orgs/beyondcode/repos')->json()
) /*?->count()*/
->filter(function ($repo) {
$repo['full_name']; //?
return Str::contains($repo['full_name'], 'laravel');
})/*?->count()*/
->map(function ($repo) {
return $repo['full_name'];
});
Eric L. Barnes, Creator of Laravel News
“I use Tinkerwell all the time now. Love that app.”

Eric L. Barnes

Creator of Laravel News

Dom Thomas, Developer
“Since I use Tinkerwell, my productivity has increased, it saves me a lot of time and more and more with each new version.”
Dom Thomas

Developer

Tinkerwell: The PHP Scratchpad

The must-have companion to your favorite IDE. Quickly iterate on PHP code within the context of your web application.

Buy now Learn more