original_string: public static function checkUserInput($input, $fields = null, $ref = null, &$errCount = 0) {
  		if( !isset($errCount) ) {
  			$errCount = 0;
  		}
  		// Allow reversed parameters 2 & 3 - Declared as useless
  		// 		if( !is_array($fields) && !is_object($ref) ) {
  		// 			$tmp = $fields; $fields = $ref; $ref = $tmp; unset($tmp);
  		// 		}
  		// 		if( is_null($ref) && is_object($ref) ) {
  		// 			$ref = $fields;
  		// 			$fields = null;
  		// 		}
  		if( is_array(static::$validator) ) {
  			if( $fields === null ) {
  				$fields = static::$editableFields;
  			}
  			if( empty($fields) ) {
  				return array();
  			}
  			$data = array();
  			foreach( $fields as $field ) {
  				// If editing the id field
  				if( $field == static::$IDFIELD ) {
  					continue;
  				}
  				$value = $notset = null;
  				try {
  					try {
  						// Field to validate
  						if( !empty(static::$validator[$field]) ) {
  							$checkMeth = static::$validator[$field];
  							// If not defined, we just get the value without check
  							$value = static::$checkMeth($input, $ref);
  							
  							// Field to NOT validate
  						} else if( array_key_exists($field, $input) ) {
  							$value = $input[$field];
  						} else {
  							$notset = 1;
  						}
  						if( !isset($notset) &&
  							($ref === null || $value != $ref->$field) &&
  							($fields === null || in_array($field, $fields))
  						) {
  							$data[$field] = $value;
  						}
  						
  					} catch( UserException $e ) {
  						if( $value === null && isset($input[$field]) ) {
  							$value = $input[$field];
  						}
  						throw InvalidFieldException::from($e, $field, $value);
  					}
  					
  				} catch( InvalidFieldException $e ) {
  					$errCount++;
  					reportError($e, static::getDomain());
  				}
  			}
  			return $data;
  			
  		} else if( is_object(static::$validator) ) {
  			if( method_exists(static::$validator, 'validate') ) {
  				return static::$validator->validate($input, $fields, $ref, $errCount);
  			}
  		}
  		return array();
  	}
code: public static function checkUserInput($input, $fields = null, $ref = null, &$errCount = 0) {
  		if( !isset($errCount) ) {
  			$errCount = 0;
  		}
  		// Allow reversed parameters 2 & 3 - Declared as useless
  		// 		if( !is_array($fields) && !is_object($ref) ) {
  		// 			$tmp = $fields; $fields = $ref; $ref = $tmp; unset($tmp);
  		// 		}
  		// 		if( is_null($ref) && is_object($ref) ) {
  		// 			$ref = $fields;
  		// 			$fields = null;
  		// 		}
  		if( is_array(static::$validator) ) {
  			if( $fields === null ) {
  				$fields = static::$editableFields;
  			}
  			if( empty($fields) ) {
  				return array();
  			}
  			$data = array();
  			foreach( $fields as $field ) {
  				// If editing the id field
  				if( $field == static::$IDFIELD ) {
  					continue;
  				}
  				$value = $notset = null;
  				try {
  					try {
  						// Field to validate
  						if( !empty(static::$validator[$field]) ) {
  							$checkMeth = static::$validator[$field];
  							// If not defined, we just get the value without check
  							$value = static::$checkMeth($input, $ref);
  							
  							// Field to NOT validate
  						} else if( array_key_exists($field, $input) ) {
  							$value = $input[$field];
  						} else {
  							$notset = 1;
  						}
  						if( !isset($notset) &&
  							($ref === null || $value != $ref->$field) &&
  							($fields === null || in_array($field, $fields))
  						) {
  							$data[$field] = $value;
  						}
  						
  					} catch( UserException $e ) {
  						if( $value === null && isset($input[$field]) ) {
  							$value = $input[$field];
  						}
  						throw InvalidFieldException::from($e, $field, $value);
  					}
  					
  				} catch( InvalidFieldException $e ) {
  					$errCount++;
  					reportError($e, static::getDomain());
  				}
  			}
  			return $data;
  			
  		} else if( is_object(static::$validator) ) {
  			if( method_exists(static::$validator, 'validate') ) {
  				return static::$validator->validate($input, $fields, $ref, $errCount);
  			}
  		}
  		return array();
  	}
code_tokens: public static function checkUserInput ( $ input , $ fields = null , $ ref = null , & $ errCount = 0 ) { if ( ! isset ( $ errCount ) ) { $ errCount = 0 ; } // Allow reversed parameters 2 & 3 - Declared as useless // 		if( !is_array($fields) && !is_object($ref) ) { // 			$tmp = $fields; $fields = $ref; $ref = $tmp; unset($tmp); // 		} // 		if( is_null($ref) && is_object($ref) ) { // 			$ref = $fields; // 			$fields = null; // 		} if ( is_array ( static :: $ validator ) ) { if ( $ fields === null ) { $ fields = static :: $ editableFields ; } if ( empty ( $ fields ) ) { return array ( ) ; } $ data = array ( ) ; foreach ( $ fields as $ field ) { // If editing the id field if ( $ field == static :: $ IDFIELD ) { continue ; } $ value = $ notset = null ; try { try { // Field to validate if ( ! empty ( static :: $ validator [ $ field ] ) ) { $ checkMeth = static :: $ validator [ $ field ] ; // If not defined, we just get the value without check $ value = static :: $ checkMeth ( $ input , $ ref ) ; // Field to NOT validate } else if ( array_key_exists ( $ field , $ input ) ) { $ value = $ input [ $ field ] ; } else { $ notset = 1 ; } if ( ! isset ( $ notset ) && ( $ ref === null || $ value != $ ref -> $ field ) && ( $ fields === null || in_array ( $ field , $ fields ) ) ) { $ data [ $ field ] = $ value ; } } catch ( UserException $ e ) { if ( $ value === null && isset ( $ input [ $ field ] ) ) { $ value = $ input [ $ field ] ; } throw InvalidFieldException :: from ( $ e , $ field , $ value ) ; } } catch ( InvalidFieldException $ e ) { $ errCount ++ ; reportError ( $ e , static :: getDomain ( ) ) ; } } return $ data ; } else if ( is_object ( static :: $ validator ) ) { if ( method_exists ( static :: $ validator , 'validate' ) ) { return static :: $ validator -> validate ( $ input , $ fields , $ ref , $ errCount ) ; } } return array ( ) ; }
docstring: Check user input
  
  @param array $input The user input data to check.
  @param string[] $fields The array of fields to check. Default value is null.
  @param PermanentObject $ref The referenced object (update only). Default value is null.
  @param int $errCount The resulting error count, as pointer. Output parameter.
  @return array The valid data.
  
  Check if the class could generate a valid object from $input.
  The method could modify the user input to fix them but it must return the data.
  The data are passed through the validator, for different cases:
  - If empty, this function return an empty array.
  - If an array, it uses an field => checkMethod association.
docstring_tokens: Check user input