Skip to content

Commit

Permalink
Finish PHP 4 constructor deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Mar 31, 2015
1 parent db76b70 commit 6ef9216
Show file tree
Hide file tree
Showing 53 changed files with 138 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Zend/tests/bug31177-2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ Bug #31177 (memory corruption because of incorrect refcounting)
--FILE--
<?php
class foo {
function foo($n=0) {
function __construct($n=0) {
if($n) throw new Exception("new");
}
}
$x = new foo();
try {
$y=$x->foo(1);
$y=$x->__construct(1);
} catch (Exception $e) {
var_dump($x);
}
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/bug38942.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class bar extends foo {
}
print_r(get_class_methods("bar"));
?>
--EXPECT--
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in %s on line %d
Array
(
[0] => foo
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/bug39127.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var_dump(is_callable(array($b,"__construct")));
echo "Done\n";
?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in %s on line %d
string(13) "a::a() called"
bool(true)
bool(false)
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/bug40784.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $b = new B;
echo "Done\n";
?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d
I'm A
I'm A
Done
2 changes: 2 additions & 0 deletions Zend/tests/bug43323.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ abstract class bar {
class foo extends bar {
}
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; bar has a deprecated constructor in %s on line %d

Fatal error: Class foo contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (bar::bar) in %sbug43323.php on line 7
6 changes: 2 additions & 4 deletions Zend/tests/bug46381.phpt
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
--TEST--
Bug #46381 (wrong $this passed to internal methods causes segfault)
--SKIPIF--
<?php if (!extension_loaded("spl")) die("skip SPL is no available"); ?>
--FILE--
<?php

class test {
public function test() {
public function method() {
return ArrayIterator::current();
}
}
$test = new test();
$test->test();
$test->method();

echo "Done\n";
?>
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug47343.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class A

class B
{
public function B($A)
public function __construct($A)
{
$this->A = $A;
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug48215_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class a {
}
class b extends a {}
class c extends b {
function C() {
function __construct() {
b::b();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/bug50261.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class testClass2 extends testClass {
new testClass2;

?>
--EXPECT--
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; testClass has a deprecated constructor in %s on line %d
testClass::testClass (1)
testClass::testClass (2)
testClass::testClass (3)
Expand Down
9 changes: 8 additions & 1 deletion Zend/tests/bug52051.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class C extends B {
new C();

?>
--EXPECT--
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; AA has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; CC has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; C has a deprecated constructor in %s on line %d
foo
bar
2 changes: 1 addition & 1 deletion Zend/tests/bug52160.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ class baz {

?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class foo in %s on line %d
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; baz has a deprecated constructor in %s on line %d

Fatal error: Constructor baz::baz() cannot be static in %s on line %d
2 changes: 2 additions & 0 deletions Zend/tests/dynamic_call_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ $a::$a();

?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; foo has a deprecated constructor in %s on line %d

Fatal error: Non-static method foo::foo() cannot be called statically in %s on line %d
16 changes: 8 additions & 8 deletions Zend/tests/get_class_methods_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ get_class_methods(): Testing scope
--FILE--
<?php

abstract class A {
abstract class X {
public function a() { }
private function b() { }
protected function c() { }
}

class B extends A {
class Y extends X {
private function bb() { }

static public function test() {
var_dump(get_class_methods('A'));
var_dump(get_class_methods('B'));
var_dump(get_class_methods('X'));
var_dump(get_class_methods('Y'));
}
}


var_dump(get_class_methods('A'));
var_dump(get_class_methods('B'));
var_dump(get_class_methods('X'));
var_dump(get_class_methods('Y'));


B::test();
Y::test();

?>
--EXPECT--
--EXPECTF--
array(1) {
[0]=>
string(1) "a"
Expand Down
14 changes: 7 additions & 7 deletions Zend/tests/get_class_methods_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ get_class_methods(): Testing scope
--FILE--
<?php

interface A {
interface I {
function aa();
function bb();
static function cc();
}

class C {
class X {
public function a() { }
protected function b() { }
private function c() { }
Expand All @@ -19,22 +19,22 @@ class C {
static private function static_c() { }
}

class B extends C implements A {
class Y extends X implements I {
public function aa() { }
public function bb() { }

static function cc() { }

public function __construct() {
var_dump(get_class_methods('A'));
var_dump(get_class_methods('B'));
var_dump(get_class_methods('C'));
var_dump(get_class_methods('I'));
var_dump(get_class_methods('Y'));
var_dump(get_class_methods('X'));
}

public function __destruct() { }
}

new B;
new Y;

?>
--EXPECT--
Expand Down
3 changes: 0 additions & 3 deletions Zend/tests/objects_010.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
--TEST--
redefining constructor (__construct second)
--INI--
error_reporting=8191
--FILE--
<?php

Expand All @@ -15,5 +13,4 @@ class test {
echo "Done\n";
?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class test in %s on line %d
Done
2 changes: 2 additions & 0 deletions Zend/tests/return_types/023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class Foo {
}

--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Foo has a deprecated constructor in %s on line %d

Fatal error: Constructor %s::%s() cannot declare a return type in %s on line %s
2 changes: 2 additions & 0 deletions Zend/tests/traits/bug55554b.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ $o = new ReportCollision;

--EXPECTF--
OverridingIsSilent1 __construct

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OverridingIsSilent2 has a deprecated constructor in %s on line %d
OverridingIsSilent2 OverridingIsSilent2

Fatal error: ReportCollision has colliding constructor definitions coming from traits in %s on line %d
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/traits/noctor001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var_dump($rbarfoo->isConstructor());
$rbarbar = new ReflectionMethod('Bar::Bar');
var_dump($rbarbar->isConstructor());
?>
--EXPECT--
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Bar has a deprecated constructor in %s on line %d
bool(false)
bool(false)
bool(true)
5 changes: 5 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4947,6 +4947,11 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */

zend_compile_stmt(stmt_ast);

if (ce->num_traits == 0) {
/* For traits this check is delayed until after trait binding */
zend_check_deprecated_constructor(ce);
}

if (ce->constructor) {
ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
Expand Down
2 changes: 1 addition & 1 deletion ext/mbstring/tests/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class tc
public $s1 = '日本語EUC-JPの文字列';
public $s2 = 'English Text';

function tc()
function __construct()
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/mysqli_stmt_bind_result_references.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ require_once('skipifconnectfailure.inc');
private $id;
public $id_ref;
public function __construct() {
parent::construct();
parent::__construct();
$this->id_ref = &$this->id;
}
}
Expand Down
4 changes: 2 additions & 2 deletions ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ $st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo')));

class foo {
public function foo($x) {
public function method($x) {
return "--- $x ---";
}
}
class bar extends foo {
public function __construct($db) {
$st = $db->query('SELECT * FROM testing');
var_dump($st->fetchAll(PDO::FETCH_FUNC, array($this, 'parent::foo')));
var_dump($st->fetchAll(PDO::FETCH_FUNC, array($this, 'parent::method')));
}

static public function test($x, $y) {
Expand Down
3 changes: 2 additions & 1 deletion ext/reflection/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ try {
}

echo "===DONE===\n";?>
--EXPECT--
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in %s on line %d
Non-object passed to Invoke()
Given object is not an instance of the class this method was declared in
===DONE===
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ foreach ($classes as $class) {

?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; B has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; C has a deprecated constructor in %s on line %d
Constructor of NewCtor: __construct
Constructor of ExtendsNewCtor: __construct
Constructor of OldCtor: OldCtor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ var_dump($reflectionClass->IsInstantiable(0, null));

?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d

Warning: ReflectionClass::isInstantiable() expects exactly 0 parameters, 1 given in %s on line %d
NULL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ foreach($classes as $class ) {

?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; publicCtorOld has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; protectedCtorOld has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; privateCtorOld has a deprecated constructor in %s on line %d
Is noCtor instantiable? bool(true)
Is publicCtorNew instantiable? bool(true)
Is protectedCtorNew instantiable? bool(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ try {
}
?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d
In constructor of class A
In constructor of class A
object(A)#%d (0) {
Expand All @@ -95,4 +96,4 @@ Access to non-public constructor of class C
Access to non-public constructor of class D
object(E)#%d (0) {
}
Class E does not have a constructor, so you cannot pass any constructor arguments
Class E does not have a constructor, so you cannot pass any constructor arguments
3 changes: 2 additions & 1 deletion ext/reflection/tests/ReflectionClass_newInstance_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ try {
}
?>
--EXPECTF--
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d
In constructor of class A
In constructor of class A
object(A)#%d (0) {
Expand All @@ -95,4 +96,4 @@ Access to non-public constructor of class C
Access to non-public constructor of class D
object(E)#%d (0) {
}
Class E does not have a constructor, so you cannot pass any constructor arguments
Class E does not have a constructor, so you cannot pass any constructor arguments
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var_dump($methodInfo->isConstructor());

?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d
New-style constructor:
bool(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ foreach ($classes as $class) {

?>
--EXPECTF--
Strict Standards: Redefining already defined constructor for class OldAndNewCtor in %s on line %d
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OldCtor has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; B has a deprecated constructor in %s on line %d

Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; C has a deprecated constructor in %s on line %d
Constructor of NewCtor: __construct
Constructor of ExtendsNewCtor: __construct
Constructor of OldCtor: OldCtor
Expand Down
Loading

0 comments on commit 6ef9216

Please sign in to comment.