note 123665 added to function.max

From: Date: Thu, 07 Mar 2019 15:29:42 +0000
Subject: note 123665 added to function.max
Groups: php.notes 
Request: Send a blank email to php-notes+get-210333@lists.php.net to get a copy of this message
Be careful using max() with objects, as it returns a reference not a new object. <?php $min_date = date_create('2019-03-05'); $max_date = date_create('2019-03-06'); $date_by_reference = max($min_date, $max_date); // $date_by_reference and $max_date are now the same object echo '$max_date is ' . date_format($max_date, 'Y-m-d') . PHP_EOL; // '2019-03-06' echo '$date_by_reference is ' . date_format($date_by_reference, 'Y-m-d') . PHP_EOL; // '2019-03-06' date_add($date_by_reference, date_interval_create_from_date_string('1 days')); // Add 1 day to $date_by_reference, changes $max_date too echo '$max_date is changed ' . date_format($max_date, 'Y-m-d') . PHP_EOL; // '2019-03-07' echo '$date_by_reference is changed ' . date_format($date_by_reference, 'Y-m-d') . PHP_EOL; // '2019-03-07' ?> ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.34 (proxied: 74.123.74.66) ---- Manual Page -- http://php.net/manual/en/function.max.php Edit -- https://master.php.net/note/edit/123665 Del: integrated -- https://master.php.net/note/delete/123665/integrated Del: useless -- https://master.php.net/note/delete/123665/useless Del: bad code -- https://master.php.net/note/delete/123665/bad+code Del: spam -- https://master.php.net/note/delete/123665/spam Del: non-english -- https://master.php.net/note/delete/123665/non-english Del: in docs -- https://master.php.net/note/delete/123665/in+docs Del: other reasons-- https://master.php.net/note/delete/123665 Reject -- https://master.php.net/note/reject/123665 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210333) next »