php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31701 (mis-) use of undeclared attributes
Submitted: 2005-01-26 03:10 UTC Modified: 2010-12-20 11:49 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: attibln at gmx dot net Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-01-26 03:10 UTC] attibln at gmx dot net
Description:
------------
Defining an attribute within a method is possible even if it was not declared in the class.

This is some kind of hidden/ghost attributes ... if they have not been declared - e.g. public name etc. - it will be quite hard to understand a class using those "ghost attribute". Especially when the are defined in method bar() and later on used in method foo().

My system:
gentoo 2.4.26-gentoo-r9
apache 2.0.51-r1
PHP Version 5.0.3 / Zend Engine v2.0.3

(php) use flags:
-adabas +apache2 -bcmath -berkdb -birdstep +bzlib -calendar -cdb -cpdflib +crypt -ctype +curl +curlwrappers -db2 -dba -dbase -dbm -dbmaker -dbx -debug -dio -empress -empress-bcs -esoob +exif -fam -fdftk -filepro -flatfile -frontbase -ftp +gd -gd-external -gdbm -gmp -hyperwave-api -iconv -imap -informix -ingres -inifile -interbase -iodbc +jpeg -kerberos -ldap -libedit -mcve +memlimit -mhash +mime -ming -mnogosearch -msession -msql -mssql +mysql -mysqli +ncurses -nis +nls -oci8 -odbc -oracle7 -ovrimos +pcntl -pcre -pfpro +png -posix +postgres -qdbm -readline -recode -sapdb -sasl +session -shared -sharedmem +simplexml -snmp +soap +sockets -solid -spell +spl -sqlite +ssl -sybase -sybase-ct -sysvipc +tidy -tiff +tokenizer -truetype -wddx +xml2 -xmlrpc -xpm +xsl +zlib

Reproduce code:
---------------
<?php

class MyDestructableClass {
  function __construct() {
    $this->nev = "MyDestructableClass";
  }

  function show_nev()
  {
    print( '<br />nev is ' . $this->nev );
  }
}

$obj = new MyDestructableClass();
$obj->show_nev();

?>


Expected result:
----------------
There should be an Error messagen ( or at least a warning) saying: 

Use of undeclared attribute in ... on line ...

Actual result:
--------------
regarding my "example":

nev is MyDestructableClass

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-26 09:05 UTC] derick@php.net
THis is wanted behavior, as not to break scripts with PHP 4.
 [2005-01-26 19:50 UTC] attibln at gmx dot net
Well, there sould be a Notice then.

We agree, this behaviour is not (really) object oriented behaviour, do we? So if it's kept for backward compatibility php5+ should show a notice.
 [2005-01-28 23:19 UTC] tony2001@php.net
Reclassified as feature request as there is no bug here.
 [2005-01-29 18:01 UTC] attibln at gmx dot net
thx :)
 [2006-04-04 09:51 UTC] tony2001@php.net
This won't change in the nearest future.
 [2006-04-04 18:39 UTC] helly@php.net
Won't change anytime - this is by design.
 [2010-12-20 11:49 UTC] jani@php.net
-Package: Tidy +Package: Scripting Engine problem
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 17:01:31 2024 UTC