# How to Read an Unfamiliar PHP Codebase

[Original page](https://codewithphp.com/learn/read-a-php-codebase/)

> Find an application's entry point, follow a PHP request into its handler, and verify a small change in a working demo.

Pick one observable behaviour before you open the code. In this walkthrough, you will find how a PHP application renders the **About Us** page and change its heading.

## Run the example and confirm what you see

Use a local copy of the [Code with PHP repository](https://github.com/dalehurley/codewithphp). From the repository root, run these commands in a terminal. The example needs PHP and uses a local server.

```sh
cd code/php-basics/17-router
php -S 127.0.0.1:8000 index.php
```

Open the [local About page](http://127.0.0.1:8000/about). Expect the heading **About Us** and the sentence **We are learning PHP routing!**. In the browser's Network panel, check the method and response status for the page. It should show a GET and a 200 response.

## Trace the request

1. Open `index.php`, the entry point used by the development server command. It loads `Router.php`, creates a router, and registers the routes. Find the line with `$router->get('/about'`.
2. Follow `$router->dispatch()` at the bottom of `index.php` into `Router.php`. That method reads the request method and URL. It tests the path against registered routes for that method.
3. When the router finds `GET /about`, it calls the function passed in `index.php`. That function prints the heading and paragraph you saw in the browser.
4. Change the heading in that function to **About This Demo**. Refresh the page to see the new heading, then open the [local home page](http://127.0.0.1:8000/) and check that its **Home Page** heading is still present. Use **Ctrl+C** to stop the local server.

Keep a short map you can share with someone else.

```text
GET /about
  → index.php loads routes and starts dispatch
  → Router.php selects the GET /about handler
  → the handler prints the About page
```

## Apply the method to a larger project

Use the README and the run command to locate the entry point. In a web app, look for the configured document root and a file such as `public/index.php`. In a console tool, start with the executable or command name. Search for one route path, visible phrase, or function name that you can observe. Find the first handler, then follow its call to the data layer and the template or response. Locate a test for that behaviour before editing.

If the project uses Composer, open `composer.json` to find packages in `require` and namespace directories in `autoload.psr-4`. `composer.lock` records the resolved versions. Follow the namespace mapping to your application's files or use your editor's **Go to Definition**. In bigger frameworks there may be multiple layers between the URL and the code you want. A test that exercises the route can be a second way in. [Composer lesson](/series/php-basics/chapters/12-dependency-management-with-composer/) · [Trace a Laravel feature and its tests](/series/php-misconceptions/chapters/04-clean-laravel-code/)
