Skip to content

Commit

Permalink
Updated UTF8 class up to v2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
belomaxorka committed Nov 10, 2023
1 parent 2664914 commit ed2220e
Show file tree
Hide file tree
Showing 2 changed files with 619 additions and 415 deletions.
29 changes: 21 additions & 8 deletions library/includes/classes/reflection.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
<?php

if (!defined('BB_ROOT')) die(basename(__FILE__));

/**
* A class for validating method parameters to allowed types via reflection.
*
* Purpose
* Used as a more convenient multiple assert(), standing after the declaration of the methods.
* * Used as a more convenient mechanism than a big code for checking types,
* standing after the declaration of the methods.
* * Requires write correct phpDoc
*
* Features and advantage
* Features
* * Very easy to use
* * Ability to turn off on the production server
*
* Understanding
* All built-in PHP functions check the type of input variables and the "swearing", if not given.
* ReflectionTypeHint does too.
* Previously, I wrote this (the correct way, but a lot of code):
* if (! is_bool($b)) {
* trigger_error('A bool type expected in 1-st parameter, ' . gettype($b) . ' type given!', E_USER_WARNING);
* return false;
* }
* if (! is_string($s)) {
* trigger_error('A string type expected in 2-nd parameter, ' . gettype($s) . ' type given!', E_USER_WARNING);
* return false;
* }
* Now I'm doing this one line of code:
* if (! ReflectionTypeHint::isValid()) return false;
*
* WARNING
* On a production server, it is important to disable assert, that would save server resources.
* For this, use the assert_options(ASSERT_ACTIVE, false) or INI setting "assert.active 0".
* In this case ReflectionTypeHint::isValid() always returns TRUE!
* In this case ReflectionTypeHint::isValid() always immediately returns TRUE!
*
* Useful links
* http://www.ilia.ws/archives/205-Type-hinting-for-PHP-5.3.html
* http://php.net/manual/en/language.oop5.typehinting.php
*
*
* @example ReflectionTypeHint_example.php
* @link http://code.google.com/p/php5-reflection-type-hint/
* @license http://creativecommons.org/licenses/by-sa/3.0/
* @author Nasibullin Rinat
* @version 1.1.0
*/

class ReflectionTypeHint
{
protected static $hints = array(
Expand Down
Loading

0 comments on commit ed2220e

Please sign in to comment.