#50383 [Ver]: Exceptions thrown in __callStatic do not include file and line in trace.

From: Date: Fri, 04 Dec 2009 12:48:38 +0000
Subject: #50383 [Ver]: Exceptions thrown in __callStatic do not include file and line in trace.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-145414@lists.php.net to get a copy of this message
ID: 50383 Updated by: rquadling@php.net Reported By: RQuadling at GMail dot com Status: Verified Bug Type: Scripting Engine problem Operating System: * PHP Version: 5.*, 6 New Comment: The fatal error is new then! Here is a straight screen capture from my terminal. [2009/12/04 12:47:16] [Z:\] [\\richardquadling\scratch$ ] >php -v PHP 5.3.2-dev (cli) (built: Dec 4 2009 10:57:52) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies [2009/12/04 12:47:19] [Z:\] [\\richardquadling\scratch$ ] >php -n <?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()); } ^Z Array ( [0] => Array ( [function] => __callStatic [class] => myClass [type] => :: [args] => Array ( [0] => ThrowException [1] => Array ( ) ) ) [1] => Array ( [file] => Z:\- [line] => 9 [function] => ThrowException [class] => myClass [type] => :: [args] => Array ( ) ) [2] => Array ( [file] => Z:\- [line] => 13 [function] => thrower [args] => Array ( ) ) ) Previous Comments: ------------------------------------------------------------------------ [2009-12-04 12:47:57] 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()); } ?> ------------------------------------------------------------------------ [2009-12-04 12:15:47] 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 11:32:44] 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 ( ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50383&edit=1

« previous php.bugs (#145414) next »