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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 13:01:30 2025 UTC