Old syntax of class constructor. Deprecated in PHP7.

@deprecated since Moodle 3.1
549886
public function component_installer($sourcebase, $zippath, $zipfilename, $md5filename='', $destpath='') {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($sourcebase, $zippath, $zipfilename, $md5filename, $destpath);
    }
299862
public function _construct()
    {
        $this->_controller = 'adminhtml_dashboard';
        $this->_headerText = __('Dashboard');
        parent::_construct();

        /**
         * Contact sync.
         */
        $this->buttonList->add(
            'contact_sync',
            [
                'label' => __('Run Contact Sync'),
                'class' => 'primary'
            ]
        );

        /**
         * Importer sync.
         */
        $this->buttonList->add(
            'importer_sync',
            [
                'label' => __('Run Importer Sync'),
                'class' => 'primary'
            ]
        );
    }
457434
public function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($elementName, $elementLabel, $text, $attributes, $values);
    }
1040643
public function Lexer(&$parser, $start = "accept", $case = false) {
            debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
            self::__construct($parser, $start, $case);
        }
1317359
public function compile()
    {
        $indent         = '    ';
        $caseStatements = array();
        $getters        = array();
        $instances      = $this->dumper->getAllInjectedDefinitions();

        /* @var $instance GeneratorInstance */
        foreach ($instances as $name => $instance) {
            $getter = $this->normalizeAlias($name);
            $constructor = $instance->getConstructor();
            $instantiatorParams = $this->buildParams($instance->getParams());

            if ('__construct' !== $constructor) {
                // Constructor callback
                if (is_callable($constructor)) {
                    $callback = $constructor;

                    if (is_array($callback)) {
                        $class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
                        $method = $callback[1];
                    } elseif (is_string($callback) && strpos($callback, '::') !== false) {
                        list($class, $method) = explode('::', $callback, 2);
                    }

                    $callback = var_export(array($class, $method), true);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = call_user_func(%s);', $callback);
                    }
                } else if (is_string($constructor) && strpos($constructor, '->') !== false) {
                    list($class, $method) = explode('->', $constructor, 2);

                    if (!class_exists($class)) {
                        throw new InvalidArgumentException('No class found: ' . $class);
                    }

                    $factoryGetter = $this->normalizeAlias($class);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = $this->' . $factoryGetter . '()->%s(%s);', $method, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = $this->' . $factoryGetter . '()->%s();', $method);
                    }
                } else {
                    throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
                }
            } else {
                $className = '\\' . trim($this->reduceAlias($name), '\\');

                if (count($instantiatorParams)) {
                    $creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
                } else {
                    $creation = sprintf('$object = new %s();', $className);
                }
            }


            // Create method call code
            if ($instance->isShared()) {
                $creation .= "\n\nif (\$isShared) {\n" . $indent
                    . '$this->instanceManager->addSharedInstance($object, \'' . $instance->getName() . '\');'
                    . "\n}\n";
            }
            $methods = '';

            foreach ($instance->getMethods() as $methodData) {
                $methodName   = $methodData['method'];
                $methodParams = $methodData['params'];
                // Create method parameter representation
                $params = $this->buildParams($methodParams);

                if (count($params)) {
                    $methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
                }
            }

            $storage = '';

            // Start creating getter
            $getterBody = '';

            // Creation and method calls
            $getterBody .= sprintf("%s\n", $creation);
            $getterBody .= $methods;

            // Stored service
            $getterBody .= $storage;

            // End getter body
            $getterBody .= "return \$object;\n";

            $getterDef = new MethodGenerator();
            $getterDef->setName($getter);
            $getterDef->setParameter('isShared');
            $getterDef->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
            $getterDef->setBody($getterBody);
            $getters[] = $getterDef;

            // Build case statement and store
            $statement = '';
            $statement .= sprintf("%scase '%s':\n", $indent, $name);
            $statement .= sprintf("%sreturn \$this->%s(%s);\n", str_repeat($indent, 2), $getter, '$isShared');

            $caseStatements[] = $statement;
        }

        // Build switch statement
        $switch = sprintf(
            "if (%s) {\n%sreturn parent::newInstance(%s, %s, %s);\n}\n",
            '$params',
            $indent,
            '$name',
            '$params',
            '$isShared'
        );
        $switch .= sprintf(
            "switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements)
        );
        $switch .= sprintf(
            "%sdefault:\n%sreturn parent::newInstance(%s, %s, %s);\n",
            $indent,
            str_repeat($indent, 2),
            '$name',
            '$params',
            '$isShared'
        );
        $switch .= "}\n\n";

        // Build newInstance() method
        $nameParam   = new ParameterGenerator();
        $nameParam->setName('name');

        $paramsParam = new ParameterGenerator();
        $paramsParam
            ->setName('params')
            ->setType('array')
            ->setDefaultValue(array());

        $isSharedParam = new ParameterGenerator();
        $isSharedParam
            ->setName('isShared')
            ->setDefaultValue(true);

        $get = new MethodGenerator();
        $get->setName('newInstance');
        $get->setParameters(array(
            $nameParam,
            $paramsParam,
            $isSharedParam,
        ));
        $get->setBody($switch);

        // Create class code generation object
        $container = $this->getClassGenerator();
        $container
            ->setName($this->containerClass)
            ->setExtendedClass('Di')
            ->addMethods(array($get))
            ->addMEthods($getters);

        // Create PHP file code generation object
        $classFile = $this->getFileGenerator();

        $classFile->setClass($container);
        $classFile->setUse('Zend\Di\Di');

        if (null !== $this->namespace) {
            $classFile->setNamespace($this->namespace);
        }

        return $classFile;
    }
142334
function class_export( $classname, array $commentData = array() ){
		echo 
		"/**\n * Auto-generated file containing class $classname";
		foreach( $commentData as $tag => $value ){
			echo "\n * @$tag $value";
		}
		echo 
		"\n */\n",
		"\n",
		"import('PLUG.parsing.Lex');\n",
		"\n";
		// hard-define integer symbols
		// excluding re-definitions or existing symbols
		ksort( $this->names );
		foreach( $this->names as $i => $c ){
			if( ! is_int($i) ){
				continue;
			}
			if( isset($this->redefinitions[$i]) ){
				//echo "// redefinition: $c = $i \n";
			}
			else {
				echo "define( ",var_export($c,1),", $i );\n";
			}
		}
		// define subclass with overloaded members
		$i = var_export( $this->i, 1 );
		echo 
		"\n",
		"/**\n * Auto-generated Lex subclass";
		// unset page level doc block tags we don't want against the class
		unset (
			$commentData['author'], $commentData['version']
		);
		foreach( $commentData as $tag => $value ){
			echo "\n * @$tag $value";
		}
		echo 
		"\n */\n",
		"class $classname extends Lex {\n",
		"\n",
		// overload $i
		"/** @var int */\n",
		"protected \$i = $i;\n",
		"\n",
		// overload names, parent class's $names array will not need to be consulted
		"/** @var array */\n",
		"protected \$names = ",var_export( $this->names, 1 ),";\n",
		// overload literals, parent class's $literals array will not need to be consulted
		"/** @var array */\n",
		"protected \$literals = ",var_export( $this->literals, 1 ),";\n",
		"\n",
		// end class
		"}\n";
	}
25576
function code_body() {
    // Get the class code from the class docblock onwards first, so it can be
    // then processed for qualified class names.
    $class_doc_block = $this->getClassDocBlockLines();
    $class_doc_block = $this->docBlock($class_doc_block);

    $class_code = array_merge(
      $class_doc_block,
      $this->class_declaration(),
      $this->classCodeBody()
    );

    // Replace any fully-qualified classes with short class names, and keep a
    // list of the replacements to make import statements with.
    $imported_classes = [];
    $this->extractFullyQualifiedClasses($class_code, $imported_classes, $this->component_data['namespace']);

    $return = array_merge(
      $this->code_namespace(),
      $this->imports($imported_classes),
      $class_code,
      [
        '}',
      ]);
    return $return;
  }
250186
private static function getDeprecatedFunctionsFromTokens(\CodeReview\PhpFileParser $tokens, \SplFileInfo $file, $version, $maxVersion) {
		$namespace = '';
		$className = null;
		$functs = array();
		foreach ($tokens as $key => $token) {
			if ($tokens->isEqualToToken(T_INTERFACE, $key)) {
				//we don't process interfaces for deprecated functions
				break;
			}
			if ($tokens->isEqualToToken(T_NAMESPACE, $key)) {
				$pos = $key+2;
				$namespace = '';
				while (isset($tokens[$pos]) && $tokens[$pos] !== ';') {
					$namespace .= $tokens[$pos][1];
						$pos++;
				}
				$namespace = '\\' . $namespace . '\\';
			}
			if ($tokens->isEqualToToken(T_CLASS, $key)) {
				//mark class name for all following functions
				$className = $namespace . $tokens[$key+2][1];
			}

			//TODO we need to filter out closures

			if ($tokens->isEqualToToken(T_FUNCTION, $key)) {
				if ($className !== null) {
					$functionName = $className . '::' . $tokens[$key+2][1];
					try {
						$reflection = new \ReflectionMethod($className, $tokens[$key+2][1]);
					} catch (\ReflectionException $e) {
//						var_dump($className, $functionName, $e->getMessage());
						continue;
					}

				} else {
					$functionName = $tokens[$key+2][1];
					try {
						$reflection = new \ReflectionFunction($functionName);
					} catch (\ReflectionException $e) {
//						var_dump($functionName, $e->getMessage());
						continue;
					}
				}

				//check if non empty version and try go guess
				$data = array(
					'name' => $functionName,
					'version' => $version,
					'file' => $file->getPathname(),
					'line' => $token[2],
				);

				$docBlock = $reflection->getDocComment();
				if ($docBlock) {
					$info = self::getDeprecatedInfoFromDocBlock($docBlock, $maxVersion);
					if (!$info) {
						if ($version) {
							// no details, but we have version, so everything is deprecated here
							$info = array(
								'deprecated' => true,
								'version' => $version,
								'fixinfoshort' => false,
							);
						} else {
							//skipping - not deprecated
							continue;
						}
					}
					$data = array_merge($data, $info);
				}

				$functs[strtolower($functionName)] = new \CodeReview\Issues\DeprecatedIssue($data);
			}
		}
		return $functs;
	}
996092
function(class_path, constructor) {

		if (class_path in this._sources) Lava.t('Class "' + class_path + '" is already defined');
		this.constructors[class_path] = constructor;

	}
862708
private function constructor(string $class_name, array $params = null)
    {
        $this->state->category = CompilerState::CATEGORY_CONSTRUCTOR;
        $this->state->name = '';
        $params_str = '';
        if (is_array($params)){
            $params_str = $this->decorateParamsForMethodCall($params);
        }
        return $class_name . '(' . $params_str . ')';
    }
975584
public function HTML_QuickForm($formName='', $method='post', $action='', $target='', $attributes=null, $trackSubmit = false) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($formName, $method, $action, $target, $attributes, $trackSubmit);
    }
157246
public function compile()
    {
        $indent    = '    ';
        $getters   = array();
        $instances = $this->dumper->getAllInjectedDefinitions();

        /* @var $instance GeneratorInstance */
        foreach ($instances as $name => $instance) {
            $constructor = $instance->getConstructor();
            $instantiatorParams = $this->buildParams($instance->getParams());

            if ('__construct' !== $constructor) {
                // Constructor callback
                if (is_callable($constructor)) {
                    $callback = $constructor;

                    if (is_array($callback)) {
                        $class = (is_object($callback[0])) ? get_class($callback[0]) : $callback[0];
                        $method = $callback[1];
                    } elseif (is_string($callback) && strpos($callback, '::') !== false) {
                        list($class, $method) = explode('::', $callback, 2);
                    }

                    $callback = var_export(array($class, $method), true);

                    if (count($instantiatorParams)) {
                        $creation = sprintf('$object = call_user_func(%s, %s);', $callback, implode(', ', $instantiatorParams));
                    } else {
                        $creation = sprintf('$object = call_user_func(%s);', $callback);
                    }
                } else if (is_string($constructor) && strpos($constructor, '->') !== false) {
                    list($class, $method) = explode('->', $constructor, 2);

                    if (!class_exists($class)) {
                        throw new InvalidArgumentException('No class found: ' . $class);
                    }

                    if (count($instantiatorParams)) {
                        $creation = sprintf(
                            '$object = $di->get(%s)->%s(%s);',
                            var_export($class, true),
                            $method,
                            implode(', ', $instantiatorParams)
                        );
                    } else {
                        $creation = sprintf('$object = $di->get(%s)->%s();', var_export($class, true), $method);
                    }
                } else {
                    throw new InvalidArgumentException('Invalid instantiator supplied for class: ' . $name);
                }
            } else {
                $className = '\\' . trim($this->reduceAlias($name), '\\');

                if (count($instantiatorParams)) {
                    $creation = sprintf('$object = new %s(%s);', $className, implode(', ', $instantiatorParams));
                } else {
                    $creation = sprintf('$object = new %s();', $className);
                }
            }


            // Create method call code
            if ($instance->isShared()) {
                $creation .= "\n\nif (\$isShared) {\n" . $indent
                    . '$di->instanceManager()->addSharedInstance($object, \'' . $instance->getName() . '\');'
                    . "\n}\n";
            }

            $methods = '';

            foreach ($instance->getMethods() as $methodData) {
                $methodName   = $methodData['method'];
                $methodParams = $methodData['params'];
                // Create method parameter representation
                $params = $this->buildParams($methodParams);

                if (count($params)) {
                    $methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $params));
                }
            }

            // Start creating getter
            $getterBody = "function (\\Zend\\Di\\Di \$di, \$isShared) {\n";

            // Creation and method calls
            $getterBody .= $indent . str_replace("\n", "\n" . $indent, $creation) . "\n";
            $getterBody .= $indent . str_replace("\n", "\n" . $indent, $methods);

            // End getter body
            $getterBody .= "\n" . $indent . "return \$object;\n}";

            $getters[$name] = $getterBody;
        }

        $fileBody = "return array(\n";

        foreach ($getters as $name => $getterBody) {
            $fileBody .= $indent . var_export($name, true);
            $fileBody .= ' => ' . str_replace("\n", "\n" . $indent, $getterBody) . ",\n\n";
        }

        $fileBody .= ");\n";

        // Create PHP file code generation object
        $generator = $this->getFileGenerator();
        $generator->setBody($fileBody);

        return $generator;
    }
27921
public function user_filter_simpleselect($name, $label, $advanced, $field, $options) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($name, $label, $advanced, $field, $options);
    }
111440
function class_declaration() {
    if (isset($this->component_data['parent_plugin_class'])) {
      $this->component_data['parent_class_name'] = '\\' . $this->component_data['parent_plugin_class'];
    }
    elseif (isset($this->component_data['plugin_type_data']['base_class'])) {
      $this->component_data['parent_class_name'] = '\\' . $this->component_data['plugin_type_data']['base_class'];
    }

    // Set the DI interface if needed.
    $use_di_interface = FALSE;
    // We need the DI interface if this class injects services, unless a parent
    // class also does so.
    if (!empty($this->injectedServices)) {
      $use_di_interface = TRUE;

      if (isset($this->component_data['parent_plugin_class'])) {
        // TODO: violates DRY; we call this twice.
        $parent_construction_parameters = \DrupalCodeBuilder\Utility\CodeAnalysis\DependencyInjection::getInjectedParameters($this->component_data['parent_plugin_class'], 3);
        if (!empty($parent_construction_parameters)) {
          $use_di_interface = FALSE;
        }
      }
      elseif (!empty($this->component_data['plugin_type_data']['construction'])) {
        $use_di_interface = FALSE;
      }
    }

    if ($use_di_interface) {
      $this->component_data['interfaces'][] = '\Drupal\Core\Plugin\ContainerFactoryPluginInterface';
    }

    return parent::class_declaration();
  }
438978
function init() {

      /// Moodle mods:  overrides the font path and encodings

      global $CFG;

      /// A default.ttf is searched for in this order:
      ///      dataroot/lang/xx_local/fonts
      ///      dataroot/lang/xx/fonts
      ///      dirroot/lang/xx/fonts
      ///      dataroot/lang
      ///      lib/

      $currlang = current_language();
      if (file_exists("$CFG->dataroot/lang/".$currlang."_local/fonts/default.ttf")) {
          $fontpath = "$CFG->dataroot/lang/".$currlang."_local/fonts/";
      } else if (file_exists("$CFG->dataroot/lang/$currlang/fonts/default.ttf")) {
          $fontpath = "$CFG->dataroot/lang/$currlang/fonts/";
      } else if (file_exists("$CFG->dirroot/lang/$currlang/fonts/default.ttf")) {
          $fontpath = "$CFG->dirroot/lang/$currlang/fonts/";
      } else if (file_exists("$CFG->dataroot/lang/default.ttf")) {
          $fontpath = "$CFG->dataroot/lang/";
      } else {
          $fontpath = "$CFG->libdir/";
      }

      $this->parameter['path_to_fonts'] = $fontpath;

      /// End Moodle mods



      $this->calculated['outer_border'] = $this->calculated['boundary_box'];

      // outer padding
      $this->calculated['boundary_box']['left']   += $this->parameter['outer_padding'];
      $this->calculated['boundary_box']['top']    += $this->parameter['outer_padding'];
      $this->calculated['boundary_box']['right']  -= $this->parameter['outer_padding'];
      $this->calculated['boundary_box']['bottom'] -= $this->parameter['outer_padding'];

      $this->init_x_axis();
      $this->init_y_axis();
      $this->init_legend();
      $this->init_labels();

      //  take into account tick lengths
      $this->calculated['bottom_inner_padding'] = $this->parameter['x_inner_padding'];
      if (($this->parameter['x_ticks_colour'] != 'none') && ($this->parameter['tick_length'] < 0))
        $this->calculated['bottom_inner_padding'] -= $this->parameter['tick_length'];
      $this->calculated['boundary_box']['bottom'] -= $this->calculated['bottom_inner_padding'];

      $this->calculated['left_inner_padding'] = $this->parameter['y_inner_padding'];
      if ($this->parameter['y_axis_text_left']) {
        if (($this->parameter['y_ticks_colour'] != 'none') && ($this->parameter['tick_length'] < 0))
          $this->calculated['left_inner_padding'] -= $this->parameter['tick_length'];
      }
      $this->calculated['boundary_box']['left'] += $this->calculated['left_inner_padding'];

      $this->calculated['right_inner_padding'] = $this->parameter['y_inner_padding'];
      if ($this->parameter['y_axis_text_right']) {
        if (($this->parameter['y_ticks_colour'] != 'none') && ($this->parameter['tick_length'] < 0))
          $this->calculated['right_inner_padding'] -= $this->parameter['tick_length'];
      }
      $this->calculated['boundary_box']['right'] -= $this->calculated['right_inner_padding'];

      // boundaryBox now has coords for plotting area.
      $this->calculated['inner_border'] = $this->calculated['boundary_box'];

      $this->init_data();
      $this->init_x_ticks();
      $this->init_y_ticks();
    }
629457
public function calc_formula($formula, $params=false) {
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
        self::__construct($formula, $params);
    }
376437
public static function getFormula(
        PhpParser\Node\Expr $conditional,
        $this_class_name,
        FileSource $source,
        Codebase $codebase = null,
        bool $inside_negation = false
    ) {
        if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd ||
            $conditional instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
        ) {
            $left_assertions = self::getFormula(
                $conditional->left,
                $this_class_name,
                $source,
                $codebase,
                $inside_negation
            );

            $right_assertions = self::getFormula(
                $conditional->right,
                $this_class_name,
                $source,
                $codebase,
                $inside_negation
            );

            return array_merge(
                $left_assertions,
                $right_assertions
            );
        }

        if ($conditional instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
            $conditional instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
        ) {
            // at the moment we only support formulae in CNF

            $left_clauses = self::getFormula(
                $conditional->left,
                $this_class_name,
                $source,
                $codebase,
                $inside_negation
            );

            $right_clauses = self::getFormula(
                $conditional->right,
                $this_class_name,
                $source,
                $codebase,
                $inside_negation
            );

            return self::combineOredClauses($left_clauses, $right_clauses);
        }

        if ($conditional instanceof PhpParser\Node\Expr\BooleanNot) {
            if ($conditional->expr instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr) {
                $and_expr = new PhpParser\Node\Expr\BinaryOp\BooleanAnd(
                    new PhpParser\Node\Expr\BooleanNot(
                        $conditional->expr->left,
                        $conditional->getAttributes()
                    ),
                    new PhpParser\Node\Expr\BooleanNot(
                        $conditional->expr->right,
                        $conditional->getAttributes()
                    ),
                    $conditional->expr->getAttributes()
                );

                return self::getFormula(
                    $and_expr,
                    $this_class_name,
                    $source,
                    $codebase,
                    $inside_negation
                );
            }

            if ($conditional->expr instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd) {
                $and_expr = new PhpParser\Node\Expr\BinaryOp\BooleanOr(
                    new PhpParser\Node\Expr\BooleanNot(
                        $conditional->expr->left,
                        $conditional->getAttributes()
                    ),
                    new PhpParser\Node\Expr\BooleanNot(
                        $conditional->expr->right,
                        $conditional->getAttributes()
                    ),
                    $conditional->expr->getAttributes()
                );

                return self::getFormula(
                    $and_expr,
                    $this_class_name,
                    $source,
                    $codebase,
                    $inside_negation
                );
            }
        }

        AssertionFinder::scrapeAssertions(
            $conditional,
            $this_class_name,
            $source,
            $codebase,
            $inside_negation
        );

        if (isset($conditional->assertions) && $conditional->assertions) {
            $assertions = $conditional->assertions;

            $clauses = [];

            foreach ($assertions as $var => $anded_types) {
                foreach ($anded_types as $orred_types) {
                    $clauses[] = new Clause(
                        [$var => $orred_types],
                        false,
                        true,
                        $orred_types[0][0] === '='
                            || $orred_types[0][0] === '~'
                            || (strlen($orred_types[0]) > 1
                                && ($orred_types[0][1] === '='
                                    || $orred_types[0][1] === '~'))
                    );
                }
            }

            return $clauses;
        }

        return [new Clause([], true)];
    }