1.2.354. Direct Call To __clone()

Direct call to magic method __clone() was forbidden. It is allowed since PHP 7.0.

From the RFC : Doing calls like $obj->`__clone( <https://www.php.net/manual/en/language.oop5.magic.php>`_ ) is now allowed. This was the only magic method that had a compile-time check preventing some calls to it, which doesn't make sense. If we allow all other magic methods to be called, there's no reason to forbid this one.

<?php

    class Foo {
        function __clone() {}
    }

    $a = new Foo;
    $a->__clone();
?>

See also Directly calling __clone is allowed.

1.2.354.1. Connex PHP features

1.2.354.1.1. Suggestions

  • Use the clone operator to call the __clone magic method

1.2.354.1.2. Specs

Short name

Php/DirectCallToClone

Rulesets

All, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56

Exakat since

1.4.8

PHP Version

With PHP 7.0 and older

Severity

Critical

Time To Fix

Slow (1 hour)

Precision

High

Available in

Entreprise Edition, Exakat Cloud