php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55372 Trait fails when method parameter has a default
Submitted: 2011-08-05 22:20 UTC Modified: 2011-08-15 09:55 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: slowlychillin at yahoo dot com Assigned: gron (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.4.0alpha3 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: slowlychillin at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-08-05 22:20 UTC] slowlychillin at yahoo dot com
Description:
------------
My code that worked in php 5.4.0alpha2 is not working in 5.4.0alpha3. When I stripped down the code to nail down exactly where things were going wrong, it turns out that I have a trait with a method with a parameter that has a default. When I remove the default, the script works just fine. When the default is there, I get this error message showing up in my browser (Firefox 5):
"The connection was reset
The connection to the server was reset while the page was loading."


Test script:
---------------
// This does not work:
trait example_trait {
    public function example_method($example_paramter = 1) {
        echo $example_paramter;
    }
}

// This does work:
trait example_trait {
    public function example_method($example_paramter) {
        echo $example_paramter;
    }
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-05 23:36 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2011-08-05 23:36 UTC] felipe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

I can't reproduce some problem.

<?php

trait example_trait {
    public function example_method($example_paramter = 1) {
        echo $example_paramter;
    }
}

class foo {
	use example_trait;
}

$x = new foo;
$x->example_method();
 [2011-08-08 03:44 UTC] slowlychillin at yahoo dot com
Apologies for not providing a better code snippet. Here's one you can try out of the box. When I uncomment the IF block, the script will hang. But if I have it commented out, like in the example below, the script works.

<?php

trait testTrait {
	public function testMethod() {
		//if (1) {
			$letters1 = range('a', 'z', 1);
			$letters2 = range('A', 'Z', 1);
			var_dump($letters1);
			var_dump($letters2);
		//}
	}
}

class foo {
	use testTrait;
}

$x = new foo;
$x->testMethod();
?>

------------
The script works both ways in php 5.4.0alpha2. Let me know if you need any other feedback!
 [2011-08-15 08:36 UTC] gron@php.net
-Status: Feedback +Status: Verified -Assigned To: +Assigned To: gron
 [2011-08-15 09:54 UTC] gron@php.net
Automatic comment from SVN on behalf of gron
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=314933
Log: Fixed Bug #55372 Incorrect handling of literals led to memory corruption.
# Dmitry you might want to review this patch, since I split up zend_add_literal
# and added a version for post-pass_two() usage.
 [2011-08-15 09:55 UTC] gron@php.net
-Status: Verified +Status: Closed
 [2011-08-15 09:55 UTC] gron@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Fixed per SVN rev 314933.
 [2012-04-18 09:49 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b14b440c93d9069a7b15a71e2e83a948bca95d9f
Log: Fixed Bug #55372 Incorrect handling of literals led to memory corruption. # Dmitry you might want to review this patch, since I split up zend_add_literal # and added a version for post-pass_two() usage.
 [2012-07-24 23:40 UTC] rasmus@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b14b440c93d9069a7b15a71e2e83a948bca95d9f
Log: Fixed Bug #55372 Incorrect handling of literals led to memory corruption. # Dmitry you might want to review this patch, since I split up zend_add_literal # and added a version for post-pass_two() usage.
 [2013-11-17 09:36 UTC] laruence@php.net
Automatic comment on behalf of gron
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b14b440c93d9069a7b15a71e2e83a948bca95d9f
Log: Fixed Bug #55372 Incorrect handling of literals led to memory corruption. # Dmitry you might want to review this patch, since I split up zend_add_literal # and added a version for post-pass_two() usage.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 16:01:30 2025 UTC