PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #7835 define() doesn't work in a class-variable-predeclaration-function-call
Submitted:15 Nov 2000 9:06pm UTC Modified: 15 Nov 2000 9:37pm UTC
From:rl at wlp dot de Assigned to:
Status:Closed Category:Scripting Engine problem
Version:4.0.3pl1 OS:Linux
View/Vote Developer Edit Submission

Welcome! If you don't have a SVN account, you can't do anything here. You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
SVN Username: SVN Password:
Quick Fix:
Status: Assign to:
Category:
Summary:
From: rl at wlp dot de
New email:
Version: OS:
New/Additional Comment:

[15 Nov 2000 9:06pm UTC] rl at wlp dot de
<?php
#  define_does_NOT_work.php --
#
#   testing defines in php4 within predeclaratrion 
#   function calls
#   
# tested on -
#   Apache/1.3.14 (Unix) mod_ssl/2.7.1 OpenSSL/0.9.6 
#   PHP/4.0.3pl1
#
# Author: Richard Leopold <rl@wlp.de>
# 
############################################################
##

define('__KEY__','this is the KEY');
define('__VALUE__','this is the VALUE');

class TEST {

   var $test = array( __KEY__ => __VALUE__ );

   function start() {
      $this->test = array( __KEY__ => __VALUE__ );
   }

   function test_define(){
      print "Looking for define-keyed array-value: test[".
            __KEY__."] = ".
            $this->test[__KEY__];
   }
}

$test = new TEST;

print("<b>Hello, this server is a </b><br><em>".
       $SERVER_SOFTWARE.
       "</em><br><br>I think there is a BUG in PHP4:</b>".
       "<br>\n");

print("<b>A define doesn't work in a class-variable ".
       "predeclaration array-function call ".
       "with a __defined__ Parameter .... </b><br>\n");

$test->test_define();

print("<br><br>".
      "<b>But when I initialize the class-variable in a ".
      "start-function ");

$test->start();

print(", then it works:</b><br>\n");

$test->test_define();

print("<br><br>".
      "<b>regards - Richard </b>");

?>

[15 Nov 2000 9:37pm UTC] torben@php.net
Not a bug; check the manual:

  http://www.php.net/manual/language.oop.php

  Note: In PHP 4, only constant initializers for var 
  variables are allowed. Use constructors for non-constant 
  initializers.

The problem isn't with the defined constants; it's with
the array() being used in the 'var $test = array(...' line.
As noted, do this in the constructor inst

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC