silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

error in Filter and Function classes #1477

Closed alombardo83 closed 7 years ago

alombardo83 commented 7 years ago

Hi,

I'm newbie in PHP and Silex (or Symfony) so I don't pretend to be sure about what I found. I saw in classes Filter and Function a bit of code which seems to be in error. I'm not at home so I can't copy/paste the code and say the line number but in my remembers it was something like that :

__construct(string $name, ...) { $this->name = $name; ... }

It failed in my computer (PHP 7.0, Silex 2.0) so I changed it in :

__construct($name, ...) { if (!is_string($name)) { return; } $this->name = $name; ... }

And it didn't fail anymore (in fact it failed further in the code). For informations, the problem appeared when I was trying to generate a page with Twig. If you want, I can give you my code to check if it's not a problem with it or with configuration of my Wamp Server.

Thanks a lot.

crowincage commented 7 years ago

Hej newbie,

http:// www.learn-php.org

If you've something like

__construct(string $var) {}

that means that $var needs to be a string and nothing else. If you're getting an error on that - pls try to understand the error message and check $var.

Silex is a well unit tested framework (that means always assume that the error is on the coder's side - and that's you :-)).

kind regards

/cr

Am 16.01.17 um 14:47 schrieb rerou83:

Hi,

I'm newbie in PHP and Silex (or Symfony) so I don't pretend to be sure about what I found. I saw in classes Filter and Function a bit of code which seems to be in error. I'm not at home so I can't copy/paste the code and say the line number but in my remembers it was something like that :

|__construct(string $name, ...) { $this->name = $name; ... }|

It failed in my computer (PHP 7.0, Silex 2.0) so I changed it in :

|__construct($name, ...) { if (!is_string($name)) { return; } $this->name = $name; ... }|

And it didn't fail anymore (in fact it failed further in the code). For informations, the problem appeared when I was trying to generate a page with Twig. If you want, I can give you my code to check if it's not a problem with it or with configuration of my Wamp Server.

Thanks a lot.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/silexphp/Silex/issues/1477, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGNH-no_TWGVWMV_I405127hs9fMdi_ks5rS3UBgaJpZM4LkkqC.

alombardo83 commented 7 years ago

OK guy, I didn't say it's not my fault but on the tutorial I followed there is this sentence

Le type de la variable à spécifier doit obligatoirement être un nom de classe ou alors un tableau. Si vous voulez exiger un tableau, faites précéder le nom du paramètre devant être un tableau par le mot-clé array comme ceci : public function frapper(array $coups). Vous ne pouvez pas exiger autre chose : par exemple, il est impossible d'exiger un nombre entier ou une chaîne de caractères de cette façon.

So it means something like

Variable type to specify must be a class name or an array. If you need an array, you should previous name argument with "array" like this : public function frapper(array $coups). You can't force anything else : for exemple, it's impossible to force an integer or a string on this way.

bug_php I just tried it on your website and it seems I'm right. So if I made a mistake, thanks to just say it and not take me up.

stof commented 7 years ago

If the initial code was failing but the modified code works, it tells me that you are not using PHP 7.0. I strongly suspect that your code is actually running on PHP 5.x (where string typehints are indeed unsupported, but Twig 2.x does not support PHP 5.x anymore)

alombardo83 commented 7 years ago

OK I need to check but when I type php -version on CLI, I get PHP 7.0. Maybe WAMP has an option to run on V7.0 ? I'll check at home. Thanks ;)

alombardo83 commented 7 years ago

Yep, Wamp was running V5.6 thanks @stof