Back to Projects

Modern PHP Calculator

A strictly typed, object-oriented calculator showcasing modern PHP 8.1+ features and a custom UI.

About this Project

This project reinvents the classic calculator exercise by leveraging cutting-edge PHP 8 features like Enums, Readonly Properties, and Match expressions. It moves beyond simple procedural logic to a fully strict-typed, object-oriented architecture. On the frontend, it features a bespoke, accessible UI with custom spinners and select menus, ensuring a premium experience across all devices.

Features

  • Modern PHP 8 Syntax (Enums, Match, Readonly Properties)
  • Strict Typing (declare(strict_types=1))
  • Custom Accessible UI Components (Spinners, Select)
  • Responsive Mobile-First Design
  • Secure Input Sanitization

Challenges & Solutions

The Challenge

The primary challenge was modernizing a legacy concept to meet contemporary standards. Implementing strict typing and Enums required a rigorous approach to data validation. Additionally, creating custom, accessible form controls (like the select dropdown and number spinners) without relying on third-party libraries presented significant UX complexities.

The Solution

I engineered a `Calc` class using PHP 8's constructor property promotion and union types for concise, robust logic. The `match` expression replaced verbose switch statements. For the frontend, I built custom JavaScript components that maintain accessibility (ARIA) while delivering a polished visual aesthetic, ensuring form inputs behave intuitively on both desktop and mobile.