#21745 [Opn]: in_array not function as intended...

From: Date: Sun, 19 Jan 2003 11:14:30 +0000
Subject: #21745 [Opn]: in_array not function as intended...
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-30553@lists.php.net to get a copy of this message
 ID:               21745
 User updated by:  jimsonchang@yahoo.com
 Reported By:      jimsonchang@yahoo.com
 Status:           Open
 Bug Type:         Reproducible crash
 Operating System: windows95
 PHP Version:      4.3.0
 New Comment:

// functions within functions scope
function a(){

	$fruit[0] = 'apple';
	$fruit[1] = 'orange';
	
	function aa(){
		global $fruit;
		
		(array) $fruit;
		echo in_array('apple', $fruit) ? 'ok' : 'fail';
	}
	
	function ab(){
		global $fruit;
		if(in_array('apple', array('apple', 'orange'))){
			echo 'ok';
		} else {
			echo 'fail';
		}
	}
}


a();
aa(); // echo fail and Warning: in_array() [function.in-array]: Wrong
datatype for second argument
ab(); // echo ok

// global scope

$country = array('japan', 'korea');

echo in_array('japan', array('japan', 'korea')) ? 'japan -
ok' : 'japan
- fail'; // ok
echo '<br>';

echo in_array('japan', $country) ? 'japan -ok' : 'japan - fail'; // ok
echo '<br>';


// function scope

function t(){
	$country = array('Malaysia', 'Singapore');
	echo in_array('Malaysia', $country) ? 'Malaysia -ok' : 'Malaysia -
fail';
}
t(); // ok


/*
wondering ? bug : bogus;

looks like in_array() can't function well in
functions within functions scope..



May Allah bless all of us!.

sincerely,
Jimson Chang
*/


Previous Comments:
------------------------------------------------------------------------

[2003-01-19 04:53:35] jimsonchang@yahoo.com

function a(){

	$fruit[0] = 'apple';
	$fruit[1] = 'orange';
	
	function aa(){
		global $fruit;
		
		(array) $fruit;
		echo in_array('apple', $fruit) ? 'ok' : 'fail';
	}
	
	function ab(){
		global $fruit;
		if(in_array('apple', array('apple', 'orange'))){
			echo 'ok';
		} else {
			echo 'fail';
		}
	}
}


a();
aa(); // echo fail and Warning: in_array() [function.in-array]: Wrong
datatype for second argument
ab(); // echo ok

/*
wondering ? bug : bogus;


May Allah bless all of us!.

sincerely,
Jimson Chang
*/

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


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



Thread (11 messages)

« previous php.bugs (#30553) next »