[RESOLU]Super Function et dump qui ne s'execute plus...

Par Romain_, il y a 5 ans


Bonjour, j'espère que quelqu'un pourra m'aider.
Je regarde actuellement la vidéo 36 dans apprendre PHP sur le router.

Je suis les instructions sauf quand je fais un dump ou que j'appelle une super function ça ne marche plus et ça me dit par exemple pour la function "call_user_func_array" :

"Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given in C:\Users\Rominouh\OneDrive\Fichiers\PUB INTERNET\Grafikart\TRAININGS\APP CALENDRIER ZIEBA\public\index.php:20 Stack trace: #0 {main} thrown in C:\Users\Rominouh\OneDrive\Fichiers\PUB INTERNET\Grafikart\TRAININGS\APP CALENDRIER ZIEBA\public\index.php on line 20"

Si j'enlève cette function et que j'essaie de faire un dump($match), voici l'erreur :
"Fatal error: Uncaught Error: Call to undefined function dump() in C:\Users\Rominouh\OneDrive\Fichiers\PUB INTERNET\Grafikart\TRAININGS\APP CALENDRIER ZIEBA\public\index.php:19 Stack trace: #0 {main} thrown in C:\Users\Rominouh\OneDrive\Fichiers\PUB INTERNET\Grafikart\TRAININGS\APP CALENDRIER ZIEBA\public\index.php on line 19"

Mon code

<?php require '../vendor/autoload.php'; //require '../elements/header.php'; $uri= $_SERVER['REQUEST_URI']; $router = new AltoRouter(); $router->map('GET', '/', function() { echo 'Salut'; }); $router->map('GET', '/nous-contacter', function() { echo 'Nous contacter'; }); $router->map('GET', '/blog/[*:slug]-[i:id]', function($slug, $id) { echo "Je suis article $slug de id $id"; }); $match = $router->match(); **exemple 1** if ($match !== null) { call_user_func_array($match['target'], $match['params']); } **exemple 2** $match = $router->match(); dump($match); //require '../elements/footer.php';

Voilà et j'ai l'impression que c'est depuis que j'ai installé composer, est-ce que cela est lié ?
Si vous trouvez la solution, pouvez-vous me donner des pistes pour que je la trouve moi-même car j'ai bien comprendre le pourquoi du comment :-)

Merci beaucoup

8 réponses

Carouge10, il y a 5 ans

Bonjour,
que donne un var_dump($match) ? (juste en dessous de "exemple 1

Romain_, il y a 5 ans

Bonjour

Voici ce que ça renvoie :
array(3) { ["target"]=> object(Closure)#2 (0) { } ["params"]=> array(0) { } ["name"]=> NULL }

Carouge10, il y a 5 ans

d'après la doc, il vaut mieux faire ainsi

// call closure or throw 404 status if( is_array($match) && is_callable( $match['target'] ) ) { call_user_func_array( $match['target'], $match['params'] ); } else { // no route was matched header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); }

qu'elle est ton URL ?

Romain_, il y a 5 ans

Ok merci je vais essayer, je suis en localhost

Carouge10, il y a 5 ans

url exacte, ce n'est pas pour tester mais comprendre la route

Romain_, il y a 5 ans

Je vais bosser dessus demain je vous tiens informé merci

Romain_, il y a 5 ans

Salut en fait pour commencer le DUMP ne fonctionnait pas car dans mon fichier composer.json je n'avais pas appelé le code
"
},
"require-dev": {
"symfony/var-dumper": "^5.2"
}
"

Pour le reste j'ai continué le tuto et en fait mon code n'était toujours pas fini. Du coup c'est réglé :-)

Carouge10, il y a 5 ans

super, passe ton sujet en résolu