php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43141 Converting $this to int
Submitted: 2007-10-30 12:42 UTC Modified: 2007-10-30 16:52 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: felipensp at gmail dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3CVS-2007-10-30 (snap) 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: felipensp at gmail dot com
New email:
PHP Version: OS:

 

 [2007-10-30 12:42 UTC] felipensp at gmail dot com
Description:
------------
When try converter $this to string, one Catchable fatal error occur.
$this to int, only Notice...

Reproduce code:
---------------
<?php
error_reporting(E_ALL);

class foo
{
  public $test = 'foo';

  public function __construct()
  {
      $this++; // don't convert
      ++$this; // don't convert

      //$this .= '';
      // Catchable fatal error: Object of class foo could not be converted to string    
      
      $this += 1;
      // Notice: Object of class foo could not be converted to int
      
      var_dump($this); //int(2)
      
      // $this->$this;
      // Odd... Notice: Undefined property:  foo::$2
      
      var_dump($this->test); // foo
      
      var_dump($this); // int(2)
  }
}

new foo;


Expected result:
----------------
Catchable fatal error: Object of class foo could not be converted to int

Actual result:
--------------
Notice: Object of class foo could not be converted to int in /home/felipe/public_html/bug.php on line 16
int(2)
string(3) "foo"
int(2)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-30 16:52 UTC] johannes@php.net
Yes, it's inconsistent but we won't change it (soon).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Sep 20 07:00:01 2025 UTC