StaffCoder
PHP
PHPPHP 8
10 modules · 49 challengesSign up
Module 9 of 10 · 4 challenges

PHP Namespaces and Autoloading

Learn how to give classes namespaces, import and alias them with use, lay out files so Composer's PSR-4 autoloader finds every class, and split a single-file checkout into a clean namespaced package.
Finish every challenge, or complete the star challenge, to complete the module.

Challenges

4 challenges

Namespaced Invoice Classes

Sign up to unlock
—No data yetmedium
About this challenge

The rest of the shop now asks for the product class under App\Catalog and the invoice classes under App\Billing, but all three still live in the global space, so every lookup fails.

Solved in a browser IDE and graded by tests. Sign up to solve

Order Address Imports

Sign up to unlock
—No data yetmedium
About this challenge

An order needs both the billing address and the shipping address, two different classes that happen to share the same short name, and the order class currently cannot load either of them.

Solved in a browser IDE and graded by tests. Sign up to solve

Warehouse Class Layout

Sign up to unlock
—No data yetmedium
About this challenge

The warehouse classes were written in whatever files were open at the time, so the class loader cannot load any of them and every page that needs stock data fails.

Solved in a browser IDE and graded by tests. Sign up to solve

Checkout Package Split

STAR
Solving it completes the module
—No data yetmedium
About this challenge

The whole checkout lives in one long file in the global namespace, two teams now each want an Address class of their own, and nothing in that file can be loaded on demand.

Solved in a browser IDE and graded by tests. Sign up to solve

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.