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

PHP Classes and Objects

Learn how to model data with promoted constructors and visibility, keep objects immutable with readonly properties, share values through static members and class constants, compare objects by identity and by value, and build an immutable shopping cart.
Finish every challenge, or complete the star challenge, to complete the module.

Challenges

5 challenges

Catalog Product Class

Sign up to unlock
—No data yetmedium
About this challenge

The catalog builds products from loose arrays, so any script can overwrite a product's price and nobody can tell which fields a product must have.

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

Immutable Price Tags

Sign up to unlock
—No data yetmedium
About this challenge

A price change on the sale page also changed the price shown in yesterday's order history, because both screens held the same price tag and one of them edited it.

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

Shipment Weight Limits

Sign up to unlock
—No data yetmedium
About this challenge

The parcel weight limit has no single home in the code, and support cannot tell how many shipments the running process has booked.

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

Coupon Display and Matching

Sign up to unlock
—No data yetmedium
About this challenge

Coupons show up on receipts as raw object dumps, and the checkout cannot tell whether two coupons merely carry the same code and discount or are the very coupon it already applied.

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

Immutable Shopping Cart

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

Shopping carts get corrupted when one screen changes a quantity while another screen still shows the old cart, and the cart page needs a plain text summary with line totals and a grand total.

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.