Using kint($var) in /devel/php will return a Drupal message with the kint JS displayed and a stacktrace like the one below.

To reproduce:

Use simplytest.me and select devel as your module.
Enable devel and kint
Go to: /devel/php
Execute the following code:

$hello = ['hello'=> 'there'];
kint($hello);

Stack Trace:

Called from <ROOT>/sites/default/modules/devel/kint/kint.module:18 [kint()]
<ROOT>/sites/default/modules/devel/src/Form/ExecutePHP.php(50) : eval()'d code:2 [kint()]
<ROOT>/sites/default/modules/devel/src/Form/ExecutePHP.php:50 [eval()]
<ROOT>/core/lib/Drupal/Core/Form/FormSubmitter.php:111 [call_user_func_array()]
<ROOT>/core/lib/Drupal/Core/Form/FormSubmitter.php:51 [Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()]
<ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:585 [Drupal\Core\Form\FormSubmitter->doSubmitForm()]
<ROOT>/core/lib/Drupal/Core/Form/FormBuilder.php:314 [Drupal\Core\Form\FormBuilder->processForm()]
<ROOT>/core/lib/Drupal/Core/Controller/FormController.php:74 [Drupal\Core\Form\FormBuilder->buildForm()]
<ROOT>/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:123 [call_user_func_array()]
<ROOT>/core/lib/Drupal/Core/Render/Renderer.php:574 [Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()]
<ROOT>/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:124 [Drupal\Core\Render\Renderer->executeInRenderContext()]
<ROOT>/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php:97 [Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()]
<ROOT>/vendor/symfony/http-kernel/HttpKernel.php:144 [call_user_func_array()]
<ROOT>/vendor/symfony/http-kernel/HttpKernel.php:64 [Symfony\Component\HttpKernel\HttpKernel->handleRaw()]
<ROOT>/core/lib/Drupal/Core/StackMiddleware/Session.php:57 [Symfony\Component\HttpKernel\HttpKernel->handle()]
<ROOT>/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php:47 [Drupal\Core\StackMiddleware\Session->handle()]
<ROOT>/core/modules/page_cache/src/StackMiddleware/PageCache.php:99 [Drupal\Core\StackMiddleware\KernelPreHandle->handle()]
<ROOT>/core/modules/page_cache/src/StackMiddleware/PageCache.php:78 [Drupal\page_cache\StackMiddleware\PageCache->pass()]
<ROOT>/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php:47 [Drupal\page_cache\StackMiddleware\PageCache->handle()]
<ROOT>/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php:50 [Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()]
<ROOT>/vendor/stack/builder/src/Stack/StackedHttpKernel.php:23 [Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()]
<ROOT>/core/lib/Drupal/Core/DrupalKernel.php:656 [Stack\StackedHttpKernel->handle()]
<ROOT>/index.php:19 [Drupal\Core\DrupalKernel->handle()]

Comments

cgmonroe created an issue. See original summary.

akalata’s picture

I'm having the same issue on 8.x-1.0 where I wasn't yesterday. I'm digging into what else the other devs on my project may have updated -- but I'm guessing it's not coming from Devel/Kint.

Edit: I take that back; I was using 8.x-1.0-rc2 yesterday. Upgrading to 8.x-1.0 produces the issue.

pasqualle’s picture

manuel garcia’s picture

Title: kint returns javascript as message with Error on eval()'d code:2 [kint()] » Kint not working on execute PHP page

Yeah just confirming this. I know people use fancy IDEs and xdebug so this is probably low on the priority list, but /devel/php is pretty handy for testing out a few things etc. Willing to put in the time here, any direction we should take?

My guess is that its because ExecutePHP::submitForm() calls dpm() directly:

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    ob_start();
    $code = $form_state->getValue('code');
    print eval($code);
    $_SESSION['devel_execute_code'] = $code;
    dpm(ob_get_clean());
  }
manuel garcia’s picture

Status: Active » Needs review
StatusFileSize
new625 bytes

Here is a petty attempt at getting the ball rolling.

Ideally we should shoot to revamp this page and integrate it properly with kint modue. For now, with this patch, if you have kint enabled, return what you want to debug and it will be displayed with ksm().

Status: Needs review » Needs work

The last submitted patch, 5: 2911336-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joelstein’s picture

Thanks for the patch! That solution worked perfectly for me.

stefan.korn’s picture

Status: Needs work » Needs review
StatusFileSize
new655 bytes

Yes ksm() did the trick for me too. Thanks.

Maybe do the patch like this and depend on "variables dumper" that is chosen on admin/config/development/devel.

moshe weitzman’s picture

Status: Needs review » Closed (won't fix)
stefan.korn’s picture

@moshe weitzman: So it is already decided that "devel execute PHP" will be removed? From3005475 it seems that only a change in README is about to be made?

I see the risks coming with this feature and agree that this feature is not suitable for use on production sites, but on the other hand it is a very handy feature for developers i. e. for testing out code snippets on the fly.

geek-merlin’s picture

Project: Devel » Devel PHP
Component: kint » Code
Status: Closed (won't fix) » Active
geek-merlin’s picture

Status: Active » Needs work
grimreaper’s picture

Status: Needs work » Postponed (maintainer needs more info)

Hello,

For people having errors, do you have tried to change the "Variables Dumper" settings on /admin/config/development/devel without changing devel_php code?

Because either by using dpm() or devel.dumper service's message() method, it will use this config, so maybe there is no need like in comment 8 to get this config and make an if or switch statement.

grimreaper’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Hello,

Without reply I am closing the issue.

Feel free to reopen if needed.

Regards,