Skip to content

Argument #1 ($string) must be of type string #1560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lxregistry opened this issue Jan 28, 2025 · 9 comments
Closed

Argument #1 ($string) must be of type string #1560

lxregistry opened this issue Jan 28, 2025 · 9 comments

Comments

@lxregistry
Copy link

Image

@stof
Copy link
Member

stof commented Jan 28, 2025

This screenshot does not help, because it gives me a truncated info (I cannot scroll the page inside it or expand collapsible sections).
Please provide the textual representation of the stack trace instead (available in the Stack trace tab). And please actually provide it as text, not as a screenshot containing text.

Please also describe on which page you get this error (and which action you are doing) to allow reproducing the issue.

@lxregistry
Copy link
Author

lxregistry commented Jan 28, 2025

TypeError:
trim(): Argument #1 ($string) must be of type string, Symfony\Component\String\UnicodeString given

  at src/Form/DataTransformer/TagArrayToStringTransformer.php:89
  at trim()
     (src/Form/DataTransformer/TagArrayToStringTransformer.php:89)
  at App\Form\DataTransformer\TagArrayToStringTransformer->trim()
     (src/Form/DataTransformer/TagArrayToStringTransformer.php:57)
  at App\Form\DataTransformer\TagArrayToStringTransformer->reverseTransform()
     (vendor/symfony/form/Form.php:953)
  at Symfony\Component\Form\Form->normToModel()
     (vendor/symfony/form/Form.php:563)
  at Symfony\Component\Form\Form->submit()
     (vendor/symfony/form/Form.php:493)
  at Symfony\Component\Form\Form->submit()
     (vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php:107)
  at Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler->handleRequest()
     (vendor/symfony/form/Form.php:414)
  at Symfony\Component\Form\Form->handleRequest()
     (src/Controller/Admin/BlogController.php:88)
  at App\Controller\Admin\BlogController->new()
     (vendor/symfony/http-kernel/HttpKernel.php:183)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:182)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/vhosts/mydomain.com/vendor/autoload_runtime.php')
     (public_html/index.php:5)         

@lxregistry
Copy link
Author

`TypeError:
App\Entity\Post::setSlug(): Argument #1 ($slug) must be of type string, Symfony\Component\String\UnicodeString given, called in /var/www/vhosts/mydomain.com/src/Form/PostType.php on line 80

at src/Entity/Post.php:111
at App\Entity\Post->setSlug()
(src/Form/PostType.php:80)
at App\Form\PostType->App\Form{closure}()
(vendor/symfony/event-dispatcher/EventDispatcher.php:206)
at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
(vendor/symfony/event-dispatcher/EventDispatcher.php:56)
at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
(vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php:28)
at Symfony\Component\EventDispatcher\ImmutableEventDispatcher->dispatch()
(vendor/symfony/form/Form.php:558)
at Symfony\Component\Form\Form->submit()
(vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php:107)
at Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler->handleRequest()
(vendor/symfony/form/Form.php:414)
at Symfony\Component\Form\Form->handleRequest()
(src/Controller/Admin/BlogController.php:88)
at App\Controller\Admin\BlogController->new()
(vendor/symfony/http-kernel/HttpKernel.php:183)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
(vendor/symfony/http-kernel/HttpKernel.php:76)
at Symfony\Component\HttpKernel\HttpKernel->handle()
(vendor/symfony/http-kernel/Kernel.php:182)
at Symfony\Component\HttpKernel\Kernel->handle()
(vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
(vendor/autoload_runtime.php:29)
at require_once('/var/www/vhosts/mydomain.com/vendor/autoload_runtime.php')
(public_html/index.php:5)`

@lxregistry
Copy link
Author

the problem is in this code:

               // if (null === $post->getSlug() && null !== $post->getTitle()) {
                //     $post->setSlug($this->slugger->slug($post->getTitle())->lower());
                // }

                if (empty($post->getSlug()) && !empty($post->getTitle())) {
                    $slug = $this->slugger->slug($post->getTitle())->lower();
                    $string = $slug->toString();
                    if (strlen($string) > 255) {
                        throw new \Exception('Generated slug exceeds the maximum length.');
                    }
                    $post->setSlug($string);
                }

from PostType.php file

and also in this code:

        // $names = array_filter(array_unique($this->trim(u($string)->split(','))));
        $names = array_filter(array_unique(array_map('trim', u($string)->split(','))));

from TagArrayToStringTransformer

fixed with chatGPT

@stof
Copy link
Member

stof commented Jan 28, 2025

you still haven't answered my request of providing the reproducing steps

@lxregistry
Copy link
Author

lxregistry commented Jan 29, 2025

you still haven't answered my request of providing the reproducing steps

just try to add a post , in a server with php 8.4 and add for your php files strict_types

<?php declare(strict_types=1);

@xabbuh
Copy link
Member

xabbuh commented Jan 29, 2025

and add for your php files strict_types

Well, if you modify the code, you have of course make sure to do it consistently. Simply enabling strict types is not enough as you also may have to adjust some calls.

@lxregistry
Copy link
Author

and add for your php files strict_types

Well, if you modify the code, you have of course make sure to do it consistently. Simply enabling strict types is not enough as you also may have to adjust some calls.

I enabled strict_types in all php files

@xabbuh
Copy link
Member

xabbuh commented Jan 29, 2025

I understood that and that’s simply not something you can do blindly without checking if the code contained in that file needs to be adapted.

I am closing here as that’s not an issue of the demo code but how you deal with it. Thank you for understanding.

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants