php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37584 is a problem with the constructor functions
Submitted: 2006-05-25 00:56 UTC Modified: 2006-05-25 06:42 UTC
From: daniel dot forero at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.4 OS: windows, linux
Private report: No CVE-ID: None
 [2006-05-25 00:56 UTC] daniel dot forero at hotmail dot com
Description:
------------
I have a class that have a constructor function, you can study the code, the result of execute the script is diferent for the  expect

Reproduce code:
---------------
<?php
class usuario 
{
	var $nombre;
	var $edad;
	var $cargo;

	function set_name($name)
	{
		$this->$nombre=$name;
	}
	function usuario()
	{
		$this->$nombre="(Undefined)";
		$this->$edad=0;
		$this->$cargo="(not a charge)";
	}
}

$daniel = new usuario;
$daniel->set_name("daniel");
echo $daniel->$nombre;
echo '<br>';
echo $daniel->$edad;
echo '<br>';
echo $daniel->$cargo;
?>

Expected result:
----------------
daniel
0
(not a charge)

Actual result:
--------------
daniel
daniel
daniel

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-25 05:50 UTC] baby dot bjorn at yahoo dot com
It's $this->nombre not $this->$nombre
 [2006-05-25 06:42 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Access the properties without $ sign, like $this->nombre.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC