Edit report at https://bugs.php.net/bug.php?id=55372&edit=1

 ID:                 55372
 Comment by:         slowlychillin at yahoo dot com
 Reported by:        slowlychillin at yahoo dot com
 Summary:            Trait fails when method parameter has a default
 Status:             Feedback
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Windows 7
 PHP Version:        5.4.0alpha3
 Block user comment: N
 Private report:     N

 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------
[2011-08-05 23:36:34] [email protected]

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-05 22:20:42] 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;
    }
}



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55372&edit=1

Reply via email to