From: razpusni dot bg at gmail dot com
Operating system: Ubuntu
PHP version: 5.4.8
Package: *General Issues
Bug Type: Bug
Bug description:Trait crash
Description:
------------
Bug 1:
When require_once('traits/tDB.php'); is called:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection
without sending any data.
Solution 1:
-> removing
protected function initialize(){
echo 'initializing';
}
Solution 2:
-> inserting trait code directly into main file not in separate one also
works.
Bug 2:
file Singleton.php - trait
file Database.php - class
When calling Database::getInstance() in browser:
1) First execution of the script works fine - non cached probably
2) Second file execution causes:
Fatal error: Call to undefined method Database::getInstance() in ...
When renaming trait makes the script work but again only on first
execution.
Test script:
---------------
Bug 1:
trait tDB {
protected $db;
function __construct($db = null) {
echo 'here';
if($db === null)
$this->db = Database::getInstance();
else
$this->db = $db;
$this->initialize();
}
protected function initialize(){
echo 'initializing';
}
}
Bug 2:
File Singleton.php
<?php
namespace traits;
trait Singleton {
protected static $instance;
final public static function getInstance($init = false, $args = null)
{
if($init !== false){
if(!is_array($args))
static::$instance->init();
else
static::$instance->init($args);
}
return isset(static::$instance)
? static::$instance
: static::$instance = new static;
}
protected static function init() {}
}
?>
<?php
class Database {
use \traits\Singleton;
//.... some public methods
}
?>
Expected result:
----------------
Bug 1:
ability to declare initialize() in separate file.
Bug 2:
Database::getInstance() being callable.
Actual result:
--------------
Bug 1:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection
without sending any data.
Bug 2:
Fatal error: Call to undefined method Database::getInstance() in ...
--
Edit bug report at https://bugs.php.net/bug.php?id=63394&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=63394&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=63394&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=63394&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=63394&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=63394&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=63394&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=63394&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=63394&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=63394&r=support
Expected behavior: https://bugs.php.net/fix.php?id=63394&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=63394&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=63394&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=63394&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63394&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=63394&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=63394&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=63394&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63394&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=63394&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=63394&r=mysqlcfg