php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70922 php类型约束失效
Submitted: 2015-11-16 13:12 UTC Modified: 2015-12-17 10:51 UTC
From: no367 at vip dot qq dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.30 OS: Window 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: no367 at vip dot qq dot com
New email:
PHP Version: OS:

 

 [2015-11-16 13:12 UTC] no367 at vip dot qq dot com
Description:
------------
<?php
namespace test;
function text( array $arr ){
  print_r($arr);
}
//not working
text('text');

Test script:
---------------
<?php
namespace test;
function test( array $arr ){
  print_r($arr);
}
//not working
test('test');

<?php
function test( array $arr ){
  print_r($arr);
}
//is working
test('test');


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-16 14:24 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-11-16 14:24 UTC] laruence@php.net
I am not sure what the problem is?

they behavior the same to me:
PHP Catchable fatal error:  Argument 1 passed to test() must be of the type array, string given, called in /tmp/1.php on line 7

and 
PHP Catchable fatal error:  Argument 1 passed to test\test() must be of the type array, string given, called in /tmp/1.php on line 7
 [2015-11-17 01:29 UTC] no367 at vip dot qq dot com
-Status: Feedback +Status: Open
 [2015-11-17 01:29 UTC] no367 at vip dot qq dot com
In fact this is the case.

<?php
namespace test;

function error( $type, $message, $file, $line ){
	static $error;
	$error[] = array(
			'type'		=>	$type,
			'message'	=>	$message,
			'file'		=>	$file,
			'line'		=>	$line,
			'fatal'		=>	false
		);
}
set_error_handler( 'test\error' );

function test_array( array $arr ){
	print_r($arr);
}

var_dump( error_get_last() ); //why is null ?

test_array('test'); //why is print test ok?
 [2015-11-17 01:31 UTC] no367 at vip dot qq dot com
Sorry,The above code is wrong.
<?php
namespace test;

function error( $type, $message, $file, $line ){
	static $error;
	$error[] = array(
			'type'		=>	$type,
			'message'	=>	$message,
			'file'		=>	$file,
			'line'		=>	$line,
			'fatal'		=>	false
		);
}
set_error_handler( 'test\error' );

function test_array( array $arr ){
	print_r($arr);
}

test_array('test'); //why is print test ok?

var_dump( error_get_last() ); //why is null ?
 [2015-11-17 01:35 UTC] no367 at vip dot qq dot com
if comment the set_error_handler then get the desired results.
 [2015-11-17 02:24 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2015-11-17 02:25 UTC] laruence@php.net
because it's a "Catchable" fatal error
 [2015-11-17 02:42 UTC] no367 at vip dot qq dot com
Thinks!
 [2015-12-17 10:51 UTC] cmb@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC