php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53674 Example 1 does not work, contradicts Description
Submitted: 2011-01-06 17:27 UTC Modified: 2011-01-12 14:56 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: thomas dot edwards at gmail dot com Assigned: danbrown (profile)
Status: Closed Package: Calendar related
PHP Version: 5.3.5 OS: Mac OS X
Private report: No CVE-ID: None
 [2011-01-06 17:27 UTC] thomas dot edwards at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.cal-days-in-month#Examples
---

Description:
int cal_days_in_month ( int $calendar , int $month , int $year )

Example 1:
<?php
$num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
echo "There was $num days in August 2003";
?>

Clearly not a integer! Does not work!

Test script:
---------------
$num = cal_days_in_month(CAL_GREGORIAN, 8, 2003); // 31
echo "There was $num days in August 2003";


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-06 17:32 UTC] danbrown@php.net
-Status: Open +Status: Bogus
 [2011-01-06 17:32 UTC] danbrown@php.net
Since when is 31 not an integer?
 [2011-01-06 17:58 UTC] thomas dot edwards at gmail dot com
In the description it says that the first variable ($calendar) is an integer, but 
in Example 1 it’s clearly a string. And when you run the code, neither a string or 
integer seems to work.
 [2011-01-06 18:02 UTC] thomas dot edwards at gmail dot com
Just tested on a different server running 5.2.8, it accepts a string or an 
integer! So the code does work, although can’t seem to get it to work on my 5.3.5 
server, but the Example does not follow the Description.
 [2011-01-06 18:21 UTC] danbrown@php.net
-Status: Bogus +Status: Re-Opened -Assigned To: +Assigned To: danbrown
 [2011-01-06 18:21 UTC] danbrown@php.net
Ah, for the first parameter, not the return value.  Gotcha'.

The code worked perfectly fine for me on 5.3.4.  Note that the first parameter 
is not encapsulated in quotes --- it's because it's an internal persistent 
constant which evaluates to 0 (zero).  In fact, the code driving that function 
actually requires that each of the values be long, which is, of course, an 
integer variable.

You mentioned in the initial report that you're using 5.3.5 on Mac.  Are you 
using a snap or SVN checkout, or did you download the final release?

Either way, if it's not working on your 5.3.5, that may indicate that it's a bug 
in PHP itself.  What is the output of the following code?

<?php
$num = cal_days_in_month(CAL_GREGORIAN,1,2011);
echo 'CAL_GREGORIAN shows '.$num.' days this month.'.PHP_EOL;

$num = cal_days_in_month(0,2,2011);
echo 'Using zero, there are '.$num.' days next month.'.PHP_EOL;
?>
 [2011-01-12 14:56 UTC] danbrown@php.net
-Status: Re-Opened +Status: Closed
 [2011-01-12 14:56 UTC] danbrown@php.net
No response.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 21:01:28 2024 UTC