Skip to content

v2.0.1 - Modern PHP 8.1+ (Latest)

Choose a tag to compare

@iamgerwin iamgerwin released this 09 Nov 04:53
· 12 commits to main since this release

TOON PHP v2.0.1 - Modern PHP Support (Latest)

Recommended for all new projects | PHP 8.1-8.4

A lightweight, blazing-fast TOON (Token-Oriented Object Notation) library for PHP that cuts your LLM API costs by 30-60%.

🎯 Version Information

  • PHP Support: 8.1, 8.2, 8.3, 8.4
  • Branch: main
  • Status: ✅ Latest & Default

📦 Installation

# Automatic (recommended)
composer require iamgerwin/toon-php

# Force v2.x
composer require iamgerwin/toon-php:^2.0

✨ What's New in v2.0.1

Changed

  • Updated PHP requirement to 8.1+ for enum support
  • Enhanced documentation with version strategy
  • Clarified versioning: v2.x (PHP 8.1+) is recommended & default, v1.x (PHP 7.0-8.0) for legacy support

🚀 Features

  • Full Enum Support (BackedEnum, UnitEnum)
  • Modern PHP 8.1+ Syntax (constructor promotion, match expressions, arrow functions)
  • 30-60% Token Savings vs JSON
  • Zero Dependencies (pure PHP)
  • PHPStan Level 6 (strict static analysis)
  • 100% Test Coverage (29 tests, 63 assertions)
  • PSR-12 Compliant

📊 Performance

Based on official TOON benchmarks:

Use Case JSON Tokens TOON Tokens Savings
E-commerce Orders 3,245 2,170 33.1%
User Lists 150 82 45.3%
Product Catalogs 320 180 43.8%

At OpenAI's GPT-4 pricing ($0.03/1K tokens):

  • 1M API calls = $3,000 (JSON) → $1,500 (TOON)
  • Annual savings: $1,500+

🎨 Quick Example

use iamgerwin\Toon\Toon;

// Encode with enum support (PHP 8.1+)
enum Status: string {
    case Active = 'active';
    case Pending = 'pending';
}

$order = [
    'id' => 123,
    'status' => Status::Active,
    'amount' => 99.99
];

$toon = Toon::encode($order);
// Output:
//   id: 123
//   status: active
//   amount: 99.99

// Tabular format
$users = [
    ['id' => 1, 'name' => 'Alice', 'role' => 'admin'],
    ['id' => 2, 'name' => 'Bob', 'role' => 'user'],
];

echo Toon::tabular($users);
// Output:
// [2]{id,name,role}:
//   1,Alice,admin
//   2,Bob,user

📚 Documentation

🔄 Versions

  • v2.x (This Release): PHP 8.1-8.4 with modern features - Recommended
  • v1.x: PHP 7.0-8.0 compatibility - Legacy Support

📋 Full Changelog

See CHANGELOG.md for complete details.


Made with ❤️ for the PHP and AI community