16.2. Measurements in the Zend Framework

Zend_Measure supports a great number of different units of measurement. Every type of measurement is identical to a specific physical or numerical property.

The units of measurement all have a unified notation: Measurement_Type::NAME_OF_UNIT. Every unit of measurement consists of a conversion factor and a display unit.

Exemplo 16.2. The meter measurement

The meter is used for measuring lengths, so its type constant can be found in the Length class. To refer to this unit of measurement, the notation Length::METER must be used. The display unit is m.

<?php
require_once 'Zend.php';
Zend::loadClass('Zend_Measure');
// loading the Length class
Zend::loadClass('Zend_Measure_Length');

echo Zend_Measure::LENGTH;           // outputs 'Zend_Measure::LENGTH'
echo Zend_Measure_Length::STANDARD;  // outputs 'Length::METER'
echo Zend_Measure_Length::KILOMETER; // outputs 'Length::KILOMETER'

$locale = new Zend_Locale('en');
$unit = new Zend_Measure(100,Zend_Measure_Length::METER,$locale);
echo $unit;
// outputs '100 m'
?>

A detailed list can be found in the chapter Types of measurements