Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Atomzwieback's avatar

The PHP Practitioner - EP 16

Hey guys,

im not sure if this here is the right place but i will try my luck becasue i stuck with this problem since 1 day and may its becasue the course isnt really good or up2date or i miss smt.

Im not sure if i did something wrong but there two things wich confusing me. But before i want to tell you that i use PHPStrom and Mamp as dev stack.

First problem is that the "routes" in "routes.php" im not sure why the "$router" variable is not defined in the source of the tutor? PHPStorm marks it as an error. And my second problem is if i use my own mysql credentials with an password im running into an 500 error but i dont know why?

Some one got an idea how to fix this?

0 likes
15 replies
Tray2's avatar

Give us som code of what you have and it's easier to understand what you are trying to do.

Generally a 500 error means that you have a type-o or something else wrong in your code.

Atomzwieback's avatar

@tray2 I identified the problem it seems that the lection is too old because the 'Dynamic include expression' not works.

index.php

<?php

require 'core/bootstrap.php';

require Router::load('routes.php')
    ->direct(Request::uri());

it tries to load dynamicly routes but it seems not to work anymore.

routes.php

<?php



$router->define([
    '' => 'controllers/index.php',
    'about' => 'controllers/about.php',
    'about/culture' => 'controllers/about-culture.php',
    'contact' => 'controllers/contact.php'
]);

and router.php

<?php

class Router
{
    protected $routes = [];

    public static function load($file)
    {
        $router = new static;

        require $file;

        return $router;
    }

    public function define($routes)
    {
        $this->routes = $routes;
    }

    public function direct($uri)
    {
        if (array_key_exists($uri, $this->routes)) {
            return $this->routes[$uri];
        }

        throw new Exception('No route defined for this URI.');
    }
}

So im a php beginner but i dont know how to fix it.

aurawindsurfing's avatar

@atomzwieback do not stress yourself too much about it. There will be people telling you to learn basics of this and that before you touch it. But honestly Laravel is such a nice framework to work with that you will be flying in no time. You can always get back to the older stuff later.

Tray2's avatar

Before learning Laravel you should at least have a basic understanding of

  • PHP
  • Object Oriented Programming
  • HTML Especially how forms work
  • SQL
  • The Http Methods
Atomzwieback's avatar

@tray2 thats not the problem i allready know Java so i also know OOP. Currently i working with angular in my job so web development is not a new area for me but php is. So i thought this site may can help, but atm it looks like the whole stuff is just way to old, and i made the wrong decision to pay for this access.

Snapey's avatar

the php practitioner course is still valid. It is not too old. It covers php principles.

Earlier answers are confused by your posting because they don't know that the course you refer to does not use Laravel

lemmon's avatar

Yes and to add to what @snapey is saying. The PHP Practitioner is a good way to aquaint you with some of the basic concepts that laravel uses today. I went through The PHP Practioner less than a year ago I works fine.

of coarse that does not help you with your present problem.

so are you saying that it all worked up until episode 15 complete?

what are the errors exactly that you are getting "what episode did the errors happen"?

Atomzwieback's avatar

@lemmon as the title of this thread shows its the EP16 where the errors begann. The router seems not to work. Just try to get the code from github and you will see the issues. I dont want to list every bug of this episode here. Just that it not work anymore because the Router isnt able to get the routes array within dynamic linking/require statements.

lemmon's avatar

Create a .htaccess file in the root of your project and add:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path= [NC,L,QSA]

That worked for me

1 like
lemmon's avatar

@atomzwieback

the "$router" variable is not defined in the source of the tutor?

although the $router in PhpStorm routes.php says that it is not defined if you. if you place:

die(var_dump($router));

at the end of the routes.php file and then view the home page it will dump the contents of the router showing that the $router var is in fact set at run time dynamically.

Here is a link to The-PHP-Practitioner-Episode-16 completed.

I got the repo, created a virtual host setting php-learning as root, then added a .htaccess file in the root with:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path= [NC,L,QSA]

and it works.

good luck.

Please or to participate in this conversation.