php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50383 Exceptions thrown in __call / __callStatic do not include file and line in trace
Submitted: 2009-12-04 11:32 UTC Modified: 2010-03-07 03:17 UTC
From: RQuadling at GMail dot com Assigned: felipe (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
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: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2009-12-04 11:32 UTC] RQuadling at GMail dot com
Description:
------------
An exception thrown in a __callStatic() method does not store the file name or the line number in the trace.

Reproduce code:
---------------
<?php
class myClass {
	public static function __callStatic($method, $args) {
		throw new Exception("Missing static method '$method'.");
	}
}

function thrower() {
	myClass::ThrowException();
}

try {
	thrower();
} catch(Exception $e) {
	print_r($e->getTrace());
}

Expected result:
----------------
Array
(
    [0] => Array
        (
            [file] => Z:\missingstatictrace.php
            [line] => 4
            [function] => __callStatic
            [class] => myClass
            [type] => ::
            [args] => Array
                (
                    [0] => ThrowException
                    [1] => Array
                        (
                        )

                )

        )

    [1] => Array
        (
            [file] => Z:\missingstatictrace.php
            [line] => 9
            [function] => ThrowException
            [class] => myClass
            [type] => ::
            [args] => Array
                (
                )

        )

    [2] => Array
        (
            [file] => Z:\missingstatictrace.php
            [line] => 13
            [function] => thrower
            [args] => Array
                (
                )

        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [function] => __callStatic
            [class] => myClass
            [type] => ::
            [args] => Array
                (
                    [0] => ThrowException
                    [1] => Array
                        (
                        )

                )

        )

    [1] => Array
        (
            [file] => Z:\missingstatictrace.php
            [line] => 9
            [function] => ThrowException
            [class] => myClass
            [type] => ::
            [args] => Array
                (
                )

        )

    [2] => Array
        (
            [file] => Z:\missingstatictrace.php
            [line] => 13
            [function] => thrower
            [args] => Array
                (
                )

        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-04 12:15 UTC] rquadling@php.net
It seems that __call exhibits the same issue.

Further, for sub-classes which allow cascading of __call/__callStatic, 
the stack doesn't show the file/line for those.




<?php
// myClass.php
class myClass {
	public static function __callStatic($method, $args) {
		throw new Exception("Missing static method 
'$method'.");
	}
}
?>

<?php
// mySubClass.php
require_once 'myClass.php';

class mySubClass extends myClass {
	public static function __callStatic($method, $args) {
		parent::__callStatic($method, $args);
	}
}
?>

<?php
// missingTrace.php
require 'mySubClass.php';

function staticThrower() {
	mySubClass::StaticThrowException();
}

try {
	staticThrower();
} catch(Exception $e) {
	print_r($e);
}
?>

Outputs ...

Exception Object
(
    [message:protected] => Missing static method 
'StaticThrowException'.
    [string:Exception:private] =>
    [code:protected] => 0
    [file:protected] => Z:\myClass.php
    [line:protected] => 4
    [trace:Exception:private] => Array
        (
            [0] => Array
                (
                    [file] => Z:\mySubClass.php
                    [line] => 6
                    [function] => __callStatic
                    [class] => myClass
                    [type] => ::
                    [args] => Array
                        (
                            [0] => StaticThrowException
                            [1] => Array
                                (
                                )

                        )

                )

            [1] => Array
                (
                    [function] => __callStatic
                    [class] => mySubClass
                    [type] => ::
                    [args] => Array
                        (
                            [0] => StaticThrowException
                            [1] => Array
                                (
                                )

                        )

                )

            [2] => Array
                (
                    [file] => Z:\missingstatictrace3.php
                    [line] => 5
                    [function] => StaticThrowException
                    [class] => mySubClass
                    [type] => ::
                    [args] => Array
                        (
                        )

                )

            [3] => Array
                (
                    [file] => Z:\missingstatictrace3.php
                    [line] => 9
                    [function] => staticThrower
                    [args] => Array
                        (
                        )

                )

        )

    [previous:Exception:private] =>
)

 [2009-12-04 12:47 UTC] jani@php.net
Simple test that works in all branches:

<?php
class myClass {
  function __call($method, $args) {
    throw new Exception("Missing static method '$method'.");
  }
}

function thrower() {
  $foo = new myClass;
  $foo->ThrowException();
}

try {
  thrower();
} catch(Exception $e) {
  var_dump($e->getTrace());
}
?>
 [2010-03-07 03:17 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=295913
Log: - Fixed bug #50383 (Exceptions thrown in __call / __callStatic do not include file and line in trace)
 [2010-03-07 03:17 UTC] felipe@php.net
-Status: Verified +Status: Closed
 [2010-03-07 03:17 UTC] felipe@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/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-03-08 11:06 UTC] rquadling@php.net
Any chance of the win32 snapshots being turned on again?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 07:01:29 2024 UTC