note 128292 added to language.references.pass

From: Date: Mon, 06 Mar 2023 10:51:36 +0000
Subject: note 128292 added to language.references.pass
Groups: php.notes 
Request: Send a blank email to php-notes+get-220250@lists.php.net to get a copy of this message
Parameters passed by references can have default values. You can find out if a variable was actually passed by using func_num_args(): <?php function refault( & $ref = 'Do I have to be calculated?'){ echo 'NUM ARGS: '. func_num_args()."\n"; echo "ORI VALUE: {$ref}\n"; if( func_num_args() > 0 ) $ref = 'Yes, expensive to calculate result: ' . sleep(1); else $ref = 'No.'; echo "NEW VALUE: {$ref}\n"; } $result = 'Do I have to be calculated?'; refault( $result ); echo "RESULT: {$result}\n"; // NUM ARGS: 1 // ORI VALUE: Do I have to be calculated? // NEW VALUE: Yes, expensive to calculate result: 0 // RESULT: Yes, expensive to calculate result: 0 refault(); // NUM ARGS: 0 // ORI VALUE: Do I have to be calculated? // NEW VALUE: No. ?> ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 188.143.70.181) ---- Manual Page -- https://php.net/manual/en/language.references.pass.php Edit -- https://main.php.net/note/edit/128292 Del: integrated -- https://main.php.net/note/delete/128292/integrated Del: useless -- https://main.php.net/note/delete/128292/useless Del: bad code -- https://main.php.net/note/delete/128292/bad+code Del: spam -- https://main.php.net/note/delete/128292/spam Del: non-english -- https://main.php.net/note/delete/128292/non-english Del: in docs -- https://main.php.net/note/delete/128292/in+docs Del: other reasons-- https://main.php.net/note/delete/128292 Reject -- https://main.php.net/note/reject/128292 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220250) next »