codeigniter-php CI Framework core/common.php Some of the functions in question?

Source: Internet
Author: User
if ( ! function_exists('is_php')){    function is_php($version = '5.0.0')    {        static $_is_php;        $version = (string)$version;        if ( ! isset($_is_php[$version]))        {            $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;        }        return $_is_php[$version];    }}

All functions are present.

if ( ! function_exists('is_php')){}

Such a structure, does this seem a little superfluous.

Reply content:

if ( ! function_exists('is_php')){    function is_php($version = '5.0.0')    {        static $_is_php;        $version = (string)$version;        if ( ! isset($_is_php[$version]))        {            $_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;        }        return $_is_php[$version];    }}

All functions are present.

if ( ! function_exists('is_php')){}

Such a structure, does this seem a little superfluous.

It is not redundant to the framework. It is possible that the user will load their function files before loading the file.

Of course not, this is to avoid the framework's own function and the developer's function conflicts.

Easy to expand.

The framework first loads the developer's functions and then loads the system functions.

Developers only need a function of the same name, they can override the system functions.

This is also a major selling point of CI.

possible

    1. Prevents duplicate declaration errors from occurring when this file is introduced multiple times
    2. Compatible with PHP versions that provide built-in functions

The code given conforms to the first case

If you think this is a problem, you can actually solve it through a namespace.

several PHP versions feature compatibility, avoid frame-to-band functions, and developers ' function conflicts for two reasons.

1,ci is a very leisurely (long) history of the framework, in the CI up in those years, PHP there is no namespace, many new features do not support
2, I think CI such design intention, certainly not is to allow the user to rewrite these functions, because to implement inheritance and rewrite, certainly is class convenient.

1. Pre-implement some functions that PHP does not implement but may implement in the future, avoiding conflicts
2. Resolve the recurring load problem.

is not redundant for the following reasons:
1. Backward compatibility, avoid the following PHP version implemented the same name function
2. Easy for developers to expand. Look at the CI documentation and know that if developers need to rewrite the functions provided by the framework, they just have to write the function name in the same way.
CI is not a fully object-oriented framework, preserving many public functions, and without the concept of namespaces, so the framework can be extensible with this approach.

If you want to erase these,
You can use namespaces
Otherwise, the name of the duplicate conflict will be

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.