Skip to content

Instantly share code, notes, and snippets.

@FlorianWolters
Last active April 27, 2016 14:17
Show Gist options
  • Select an option

  • Save FlorianWolters/5195734 to your computer and use it in GitHub Desktop.

Select an option

Save FlorianWolters/5195734 to your computer and use it in GitHub Desktop.
Demonstrates a PHP bug: It is possible to directly call the magic method "__construct".
<?php
/**
* DirectCallToMagicMethodConstruct.php
*
* PHP 5.4.13 (cli) (built: Mar 15 2013 02:05:59)
* Copyright (c) 1997-2013 The PHP Group
* Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
* with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
*/
class Example
{
function __construct()
{
}
}
$example = new Example;
// Should raise an \E_FATAL with the following message:
// "Cannot call __construct() method on objects - use 'new <Class>' instead in [...] on line 21"
$example->__construct();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment