percent20 Posted June 19, 2008 Share Posted June 19, 2008 i have been working on a site and all was working well then one day spent sometime doing some refactoring and boom all of a sudden one thing on the site doesn't work. That is trying to pass an object. Well I should say it passes part of the object. Here is some of the code Object Data Type class Link { // fields public $id; public $link; public $title; public $desc; public $category; } Basically i am creating an object and setting the properties to the above. I then create an object that I use to do all my data stuffs with the data base and pass it the object above. Here is the basics of that. $theLink = new Link(); $theLink->id = $_POST["id"]; $theLink->link = $_POST["link"]; $theLink->title = $_POST["title"]; $theLink->desc = $_POST["desc"]; $theLink->category = $_POST["category"]; $linksData = new LinksData(); if($linksData->UpdateLink($theLink)){ } What is most intrigiung is only the $theLink->link seems to get passed when $linkData->UpdateLink($theLink) is called because it actually updates in the database. However, when I cut out that whole part all together and take everything in the UpdateLink function and put it in with the above code all works just fine. So that leads me to beleive I have a problem passing the object. For general information about my environment. PHP 5.2.5 Apache 2.0 Windows XP Pro SP2 Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 19, 2008 Share Posted June 19, 2008 There is nothing wrong with your code as is, and it should work fine. A couple notes... -are you sure the values of $_POST are being passed properly from your form? -passing an object as an argument actually passes it by reference (unlink normal number/string/array data types)...not sure if this applies to you the following code work just as expected: <?php class Link { public $id; public $link; public $title; public $desc; public $category; } class LinksData { public function UpdateLink ( $linkObj ) { print_r($linkObj); return true; } } $theLink = new Link(); $theLink->id = 123; $theLink->link = 'http://foobar.com'; $theLink->title = 'My Test Site'; $theLink->desc = 'Some notes about it'; $theLink->category = 'samples'; print_r($theLink); $linksData = new LinksData(); if($linksData->UpdateLink($theLink)){ print 'success'; } ?> Link Object ( [id] => 123 [link] => http://foobar.com [title] => My Test Site [desc] => Some notes about it [category] => samples ) Link Object ( [id] => 123 [link] => http://foobar.com [title] => My Test Site [desc] => Some notes about it [category] => samples ) success Quote Link to comment Share on other sites More sharing options...
percent20 Posted June 19, 2008 Author Share Posted June 19, 2008 i'm an idiot. it worked I just had a naming mis-match that was messing everything up. grrrrrr. I hate a wasted 5 hours on misnaming something. Thanks for the help somone else confirming that it works for sure helped me to look elsewhere and I immediatly found the problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.