php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29022 "Warning: Constants may only evaluate to scalar values" on valid constant defin
Submitted: 2004-07-05 20:18 UTC Modified: 2004-07-06 09:12 UTC
From: johfivealive at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0RC3 OS: Fedora Core 2
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: johfivealive at hotmail dot com
New email:
PHP Version: OS:

 

 [2004-07-05 20:18 UTC] johfivealive at hotmail dot com
Description:
------------
using the define() function I get a warning when I don't think I should.

Reproduce code:
---------------
define( "LOGIK_MYSQL_HOST", $config->getMySQLHost() );

where $config->getMySQLHost() returns a string.

The following code makes the warning go away:

define( "LOGIK_MYSQL_HOST", (string) $config->getMySQLHost() );

Expected result:
----------------
define( "LOGIK_MYSQL_HOST", $config->getMySQLHost() );

should not produce a warning

Actual result:
--------------
define( "LOGIK_MYSQL_HOST", $config->getMySQLHost() );

produces the following warning:

"Warning: Constants may only evaluate to scalar values"

even though $config->getMySQLHost() returns a scalar, have to cast to string in order to make the warning go away

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-06 09:12 UTC] derick@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

This is correct behavior.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 10:01:33 2025 UTC