<?php classRetailStore { useGeocodable; // Class implementation goes here }
Real implementation
The PHP interpreter copies and pastes traits into class definitions at compile time, and it does not protect against incompatibilities introduced by this action. If your PHP trait assumes a class property or method exists (that is not defined in the trait itself), be sure those properties and methods exist in the appropriate classes.
1 2 3 4 5 6 7 8 9 10
<?php $geocoderAdapter = new \Geocoder\HttpAdapter\CurlHttpAdapter(); $geocoderProvider = new \Geocoder\Provider\GoogleMapsProvider($geocoderAdapter); $geocoder = new \Geocoder\Geocoder($geocoderProvider); $store = newRetailStore(); $store->setAddress('420 9th Avenue, New York, NY 10001 USA'); $store->setGeocoder($geocoder); $latitude = $store->getLatitude(); $longitude = $store->getLongitude(); echo$latitude, ':', $longitude;