vincej Posted March 22, 2011 Share Posted March 22, 2011 I'm new to OOP and straight out the gate Dreamweaver keeps giving me an error which I do not understand. I get that $_POST creates an array, however, in the procedural world I have always been able to assign a $variable to a $_POST. In fact if I remove the Class declaration the error goes away. What am am I missing ? - Many Thanks VJ : <?php class LookUp { $first_name = $_POST["f_name"]; $last_name = $_POST ["l_name"]; $company = $_POST["company"]; } ?> Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/ Share on other sites More sharing options...
trq Posted March 22, 2011 Share Posted March 22, 2011 See http://au2.php.net/manual/en/language.oop5.properties.php Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191077 Share on other sites More sharing options...
vincej Posted March 23, 2011 Author Share Posted March 23, 2011 Thanks - Dumb mistake, but adding the 'PUBLIC' declaration still has not made any difference to Dreamweaver still complaining. Here is what I got: <?php class LookUp { public $first_name = $_POST["f_name"]; public $last_name = $_POST ["l_name"]; public $company = $_POST["company"]; } ?> Many thanks for any ideas - VJ Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191316 Share on other sites More sharing options...
AbraCadaver Posted March 23, 2011 Share Posted March 23, 2011 What is dreamweaver saying? Ooh dream weaver I believe you can get me through the night Ooh dream weaver I believe we can reach the morning light Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191320 Share on other sites More sharing options...
vincej Posted March 23, 2011 Author Share Posted March 23, 2011 HI - DW says " There is a syntax error on line 4. Code hinting may not work until you fix this error" line 4 is the first variable line ... but all the variable lines have a red mark on the margin line numbers ! Many thanks VJ Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191322 Share on other sites More sharing options...
AbraCadaver Posted March 23, 2011 Share Posted March 23, 2011 This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated. You should probably set them in a constructor: class LookUp { public $first_name; public $last_name; public $company; function __construct() { $this->first_name = $_POST["f_name"]; $this->last_name = $_POST ["l_name"]; $this->company = $_POST["company"]; } } I don't know what you're doing but this may not be the best idea because now your class is dependent on POST vars being available. Maybe more like this: class LookUp { public $first_name; public $last_name; public $company; function __construct($f_name, $l_name, $company) { $this->first_name = $f_name; $this->last_name = $l_name; $this->company = $company; } } Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191325 Share on other sites More sharing options...
vincej Posted March 23, 2011 Author Share Posted March 23, 2011 I am wanting to pull in form data and INSERT to Mysql. I can do this procedurally but I am really wanting to make the transition to OPP. I need the script to run automatically when I hit the submit button and action=look_up.php You a star - thank you. VJ Link to comment https://forums.phpfreaks.com/topic/231441-why-should-using-_post-in-a-class-create-an-error/#findComment-1191340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.