note 46914 added to language.types.string

From: Date: Wed, 27 Oct 2004 19:01:45 +0000
Subject: note 46914 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-79200@lists.php.net to get a copy of this message
You can use the complex syntax to put the value of both object properties AND object methods inside a string. For example... <?php class Test { public $one = 1; public function two() { return 2; } } $test = new Test(); echo "foo {$test->one} bar {$test->two()}"; ?> Will output "foo 1 bar 2". However, you cannot do this for all values in your namespace. Class constants and static properties/methods will not work because the complex syntax looks for the '$'. <?php class Test { const ONE = 1; } echo "foo {Test::ONE} bar"; ?> This will output "foo {Test::one} bar". Constants and static properties require you to break up the string. ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46914 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46914&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46914&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#79200) next »