generateStructPropertyError($property) ); } final public function __set($property, $value) { throw new \DomainException( $this->generateStructPropertyError($property) ); } private function generateStructPropertyError($property) { $suggestion = $this->suggestPropertyName($property); $suggestStr = ($suggestion == "") ? "" : " ... did you mean \"{$suggestion}?\""; return sprintf( "%s property \"%s\" does not exist%s", get_class($this), $property, $suggestStr ); } private function suggestPropertyName($badProperty) { $badProperty = strtolower($badProperty); $bestMatch = ""; $bestMatchPercentage = 0.00; $byRefPercentage = 0.00; foreach ($this as $property => $value) { // Never suggest properties that begin with an underscore if ($property[0] === "_") { continue; } \similar_text($badProperty, strtolower($property), $byRefPercentage); if ($byRefPercentage > $bestMatchPercentage) { $bestMatchPercentage = $byRefPercentage; $bestMatch = $property; } } return ($bestMatchPercentage >= $this->__propertySuggestThreshold) ? $bestMatch : ""; } }