PHP资源是一种已经是引用的特殊类型.通过值或通过引用明确地传递它将不会有所不同(即它仍然是参考).您可以在PHP4下自行检查:
function get_connection() {
$test = mysql_connect('localhost', 'user', 'password');
mysql_select_db('db');
return $test;
}
$conn1 = get_connection();
$conn2 = get_connection(); // "copied" resource under PHP4
$query = "INSERT INTO test_table (id, field) VALUES ('', 'test')";
mysql_query($query, $conn1);
print mysql_insert_id($conn1)."
"; // prints 1
mysql_query($query, $conn2);
print mysql_insert_id($conn2)."
"; // prints 2
print mysql_insert_id($conn1); // prints 2, would print 1 if this was not a reference