eldan88 Posted April 18, 2014 Share Posted April 18, 2014 Hey Guys. I am new to working with static properties. I have defined a satic property and trying to echo it out in a input field string. But it won't echo out. Does any one know why?? Below is my code. Thanks in advance class html_generator extends validation { public static $input_class; public function __construct() { self::$input_class = (isIphone()) ? "mobile_text_field" : ""; } //Input string I i am trying to echo out the input_class "<input type='text' id='name' name='name' class='{html_generator::$input_class}' >" Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/ Share on other sites More sharing options...
.josh Posted April 18, 2014 Share Posted April 18, 2014 you need to remove the $ in front of $input_class Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/#findComment-1476604 Share on other sites More sharing options...
eldan88 Posted April 18, 2014 Author Share Posted April 18, 2014 Oh okay. Does that only apply for strings? Because I have another static property where is put a $ infront of it... for example class::$prop and it worked fine... Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/#findComment-1476605 Share on other sites More sharing options...
eldan88 Posted April 18, 2014 Author Share Posted April 18, 2014 .josh. I tried removing the $ and it still isn't functioning properly. I even went ahead and debugged my code... Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/#findComment-1476606 Share on other sites More sharing options...
eldan88 Posted April 18, 2014 Author Share Posted April 18, 2014 The only way it works is by concatenating like so.... "<input type='text' id='name' name='name' class=". html_generator::$input_class_test . " value='{$post_values->name}' >" Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/#findComment-1476607 Share on other sites More sharing options...
KevinM1 Posted April 18, 2014 Share Posted April 18, 2014 Josh was referring to the '$' here: html_generator::$input_class Link to comment https://forums.phpfreaks.com/topic/287870-displaying-static-properties-in-a-string/#findComment-1476608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.