php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50925 Strict errors when including/requiring class files
Submitted: 2010-02-03 10:55 UTC Modified: 2010-02-03 12:40 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: pieterbregman1982 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.1 OS: Windows
Private report: No CVE-ID: None
 [2010-02-03 10:55 UTC] pieterbregman1982 at gmail dot com
Description:
------------
PHP reports a strict error when classes are being included using include() (or require()).

This error doesn't come up when the classes are in the scope allready by inlining them in the same file that makes the calls to the classes.

I can't figure out why the error only occurs when the classes are being included by using include()

Reproduce code:
---------------
test1.php (This code gives no strict errors)
<?php
ini_set('display_errors', '1');
error_reporting(-1);

abstract class Model {
	public function create() {
		echo __CLASS__;
	}
}
class Person extends Model {
	public function create($name) {
		echo $name;
	}
}

$person = new Person();
$person->create('Foo');
?>

test2.php (This code does give a strict error)
<?php
ini_set('display_errors', '1');
error_reporting(-1);

include_once 'Model.php';
include_once 'Person.php';

$person = new Person();
$person->create('Foo');
?>

Model.php
<?php
abstract class Model {
	public function create() {
		echo __CLASS__;
	}
}
?>

Person.php
<?php
class Person extends Model {
	public function create($name) {
		echo $name;
	}
}
?>

Expected result:
----------------
I would expect that both tests don't give strict errors.

Actual result:
--------------
test02.php - Strict error:
Strict standards: Declaration of Person::create() should be compatible with that of Model::create() in Person.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-03 12:05 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #50897
 [2010-02-03 12:40 UTC] pieterbregman1982 at gmail dot com
Sorry for submitting the bug more than once.

I've read the bug report and I understand now why test1.php doesn't show strict warnings and test2.php does.

What I don't understand, is the reason behind the strict error. What is the use of extending classes when it's not allowed to override methods in the child classes with different parameters?

This is also mentioned in http://bugs.php.net/bug.php?id=50897 but it remains unanswered.

Searching the bug database, I found this bug: http://bugs.php.net/bug.php?id=49177 Does the status "verified" mean that the method overriding issue has your attention? If so, is there any news around this issue?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 13 11:00:01 2025 UTC