Re: [PHP] self operator within a double quoted string
[email protected] (Marco Behnke)
| Newsgroups | php.general |
|---|---|
| Message-ID | <[email protected]> |
Am 17.04.13 20:59, schrieb Matijn Woudt: > On Wed, Apr 17, 2013 at 7:47 PM, NaMarPi <[email protected]> wrote: > >> I would like to use self and static operators inside a double quoted >> string, >> but do not find the way to accomplish that. Could you give me a right >> direction? >> >> >> http://3v4l.org/NDkdA >> >> >> class Foo { >> >> public static $class_prop = 'Class_Property'; >> public $object_prop = 'Object_Property'; >> >> static function printClassProp() { >> print 'prefix_' . self::$class_prop . '_postfix' . PHP_EOL; >> print "prefix_{\\self::$class_prop}_postfix" . PHP_EOL; // >> <-- issue here >> } >> >> function printObjectProp() { >> print "prefix_{$this->object_prop}_postfix" . PHP_EOL; >> } >> } >> >> >> $foo = new Foo; >> $foo->printObjectProp(); >> >> >> Foo::printClassProp(); >> >> > Hi, > > This is a bug/feature in php and is just not possible. Either use the > syntax you've used on the single quotes, or store the variable in a > temporary var before using the print. Or use printf which is much more readable. > > - Matijn > -- Marco Behnke Dipl. Informatiker (FH), SAE Audio Engineer Diploma Zend Certified Engineer PHP 5.3 Tel.: 0174 / 9722336 e-Mail: [email protected] Softwaretechnik Behnke Heinrich-Heine-Str. 7D 21218 Seevetal http://www.behnke.biz
signature.asc
(application/pgp-signature, 946 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJRbwPrAAoJEMsuiTvEJLXOzOgP/3RRMllOEeMLC5uc3+bt0wUT 7luy0W58xgqQCbGRUJUZSvToL39QgJDj9s+fHeiD4vkucCNiF5Op1kJnQ4if44pv +vHtrowgEewJv8bovw2tMlYx7yT49Om09iP2Qy5uZJbIJBEiPtIkZyO/LaMV40OI kR5a4WexbFEMyf8KdYEwx3hH89tafjVwkT5Jlb49nQAqELzuEMTV98FsBrx773Yn V88B7xAdw/ZZV7FnO2kiz9ud22zZUvs2N/WaQO5+19wO9pQmivNYLxgxBy0AOkye iafefeHY2JcbpnUq1p64Hr6XLKXLU6dSigss68qwFVKC1Od0dPOLcjcxlG9rA0Gn iMYgjtE8TcPo+UzvLBptR3i9LJDOsMvmY2czWD7d2TjGzdD9xxK1qn19qvlhUuQV 4vQJObVRqjkMGZGVPUI7rKB8TJXeRsoRKYl9WRmwWsmz3KZX0tsvKQmW5mDX/wWk 9J8jv+gfslglx35zb0cPMkBeoIxa0A3FC2otuA4kyo65QMQIZLl2nYlANIfgy19Z +LWyAQKnLEgecpj9ZxfImts6PYFj9K7IYcJD7a5RY2GoXZ+bfeSpnOvV1u7jYNrd 7pknyPA4H6nIQOo1p5xQoXn/Mr4IlA0CUofIMc7IKDbMyKoT0qtjhxT9ZMwouzpe JCf2cttQkg5gKAlSGOV3 =3u+2 -----END PGP SIGNATURE-----