0

so here's the situation. It is PHP 7.4, Magento 2.4.3-p1

  • On the production server, an error is showing up on the exceptions.log. It reads as follows: Class string does not exist at /var/www/public/vendor/magento/framework/Webapi/ErrorProcessor.php:208, ReflectionException(code: -1): Class string does not exist at /var/www/public/vendor/magento/framework/Reflection/MethodsMap.php:166)"} []

  • I happens daily on the production server, but it does not happen on staging, dev, and worse, I cannot replicate the error on local.

  • The method gets called when loading a PLP, PDP, homepage and checkout&shipping (maybe on even more places) and cache has been cleared (locally). On prod, I assume when someone visits the page for the first time.

  • I've put a breakpoint in the method. The method seems to load a bunch of interfaces and caches them. Some of them are:

Magento\Tax\Api\Data\TaxDetailsInterface

Magento\Catalog\Api\Data\ProductRenderInterface

\Magento\Catalog\Api\Data\ProductRender\ButtonInterface

etc...

Things I have tried

  • Running the master branch, with the production database, and in production mode. Nothing happens.
  • I've added a logger to the method in question. It just shows the interface being called, and on which page.
  • Since I think this has something to do with the phpdocs, I have tried messing around with the various phpdocs on the loaded interfaces, and the classes which implement the interfaces, but no luck.

Any ideas? Cheers!

2 Answers 2

1

It may be worth checking the used dependencies in your site.

The background of this issue can be that the developers of the site may have used IDE auto-completion feature. As a result, the word string can be completed with the class 'use Magento\Tests\NamingConvention\true\string;'.

this is a common problem and to resolve it, you may search in your codebase the string 'true\string' and if you find any, then just remove the related lines in the use sections. Magento will start using the native string type and your errors will disappear.

Of course, this answer is based on my experience and you may have a different issue. For this reason, whatever you do, please keep a backup of your codebase beforehand and maybe make one file change at a time before doing any roll out.

Good luck

2
  • Hi there, thank you for the comment. I searched the entire codebase via PHPStorm, and the only instance of true/string is in `vendor/magento/magento-coding-standard/Magento2/Sniffs/Namespaces/ImportsFromTestNamespaceSniff.md'...warning users not to import it. Ah well, I'll continue investiagting. Thank you! Commented Aug 9, 2022 at 15:57
  • This worked for me, PHP Storm added the statement use Magento\Tests\NamingConvention\true\string automatically and unknown to me when I specified string as a parameter in a function. Commented Aug 2, 2023 at 1:32
0

I faced the same problem. It is due to the return type of the response specified in the Interface file(Usually at Api/Interface.php).

Sample code:

here it is: @return \Vendor\Module\Api\Data\ResponseDataInterface

<?php
namespace Vendor\Module\Api;
interface SampleInterface
{
/**
 * GET for Post api
 * @param string $customerId
 * @return \Vendor\Module\Api\Data\ResponseDataInterface
 */
public function getDetails($customerId);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.