php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80212 Decrement operator doesn't work as stated in the manual
Submitted: 2020-10-10 10:20 UTC Modified: 2020-10-10 10:42 UTC
From: g dot a dot stamoulis at gmail dot com Assigned:
Status: Open Package: Strings related
PHP Version: 7.4.11 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: g dot a dot stamoulis at gmail dot com
New email:
PHP Version: OS:

 

 [2020-10-10 10:20 UTC] g dot a dot stamoulis at gmail dot com
Description:
------------
Strings can be incremented by the ++ operator but they don't get decremented by the -- operator. This is seems inconsistent and it is also not documented in the manual.  

Test script:
---------------
<?php
$test = 'abc12';

// increment works as expected
echo(++$test . "\n");
echo(++$test . "\n");
echo(++$test . "\n");

// decrement fails
echo(--$test . "\n");
echo(--$test . "\n");
echo(--$test . "\n");

Expected result:
----------------
abc13
abc14
abc15
abc14
abc13
abc12


Actual result:
--------------
abc13
abc14
abc15
abc15
abc15
abc15

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-10 10:42 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2020-10-10 10:42 UTC] cmb@php.net
The manual already states[1]:

| Note that character variables can be incremented but not
| decremented […]

Maybe this important note should be more prominent.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 04 08:01:28 2024 UTC