TOON PHP v2.0.2 - Documentation Enhancement
Latest Release | PHP 8.1-8.4 Support
Enhanced documentation release with comprehensive API reference and examples for better developer experience.
📚 What's New
Added
- Comprehensive DOCUMENTATION.md with complete API reference
- Detailed examples covering all features and use cases
- Performance benchmarks and cost calculations
- Best practices guide for optimal usage
- Error handling documentation with troubleshooting tips
Changed
- Enhanced documentation structure for better user onboarding
- Improved code examples with real-world scenarios (ChatGPT integration, e-commerce, user profiles)
🚀 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
📦 Installation
# Automatic (recommended for PHP 8.1+)
composer require iamgerwin/toon-php
# Force v2.x
composer require iamgerwin/toon-php:^2.0📊 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 for uniform datasets
$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
- README
- DOCUMENTATION - NEW
- CHANGELOG
🔄 Versions
- v2.x (This Release): PHP 8.1-8.4 with modern features - Recommended
- v1.x: PHP 7.0-8.0 compatibility - Legacy Support
Made with ❤️ for the PHP and AI community