PHP - Need Help Working With Property Visibility
Hey Guys. I am trying to assign a property through a method that is called in a swtich method.
After the property gets "assigned" I do a var_dump on the property and it returns NULL?
I am not sure why it returns NULL.... I would really appreciate any help...
class Tea { public $current_tea; //Current tea does not get assigned when using the AssignTea($TeaArg) function private $upcoming_tea = "Blacktea"; public function SelectTea() { $TeaType = "Black"; switch ($TeaType) { case "Black": $this->AssignTea($this->upcoming_tea); break; }// End of Swtich }// End of function SelectTea() private function AssignTea($TeaArg){ $this->current_tea = $TeaArg; } } $tea = new Tea(); var_dump($tea->current_tea); Edited by eldan88, 20 May 2014 - 10:07 AM. Similar TutorialsI just have a quick question, what happens if I don't assign a visibility element to methods? In other words, if I just have: [php] class Article_model { public $data; function index() { return $data; } [php] ...instead of declaring public, private, static, and so on before the function. Will php just consider it public? I have some questions about the scope of navigation : if i define a constant like define('constant'), php manuel says it's global, does this mean that i can use of different files also? like, i defined in define.php and used in anotherfile.php, or shoud the latter file be included then? what about file a.php includes file b.php which in turn includes file c.php. Can functions of a use variables of file c? ultimately: what about variables that are declared global inside a function but this variables is not initialized in that script, like in wordpress: function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) { global $wp_locale; // more code } $wp_locale can be initialized in another script file? thanks in advance Hi all, I have a script which I coded not long ago which works fine but there is one error which says: Notice: Trying to get property of non-object in /home/www/***-*****.com/hts.php on line 374 I carnt see why its showing the error. $fetch2=mysql_query("SELECT crew FROM users WHERE username='$username'") or die (mysql_error()); $fetch1 = mysql_fetch_object($fetch2); $crewrep1=mysql_query("SELECT * FROM crews WHERE name='$fetch1->crew'") or die (mysql_error()); $crewrep = mysql_fetch_object($crewrep1); $result = $rep + $reps; $result55 = $crewrep->rep + $reps; // Line 374 Can anyone else see why its showing the error? Thanks for your help. First let me just say, I am by no means a coder. But I am trying to set up a website for a friend.
I am no novice when it comes to the web design part, but I am one when it comes to PHP code.
That said, I have a joomla site on my local machine for the time being. I am using joomla for this site. Joomla wont help me with this problem. They refer me to the creator of the extension.
Well, problem is, I have posted there and have not had any answer yet either. The problem is when I use a form component and ue the select box option.
Anyway, the problem I am having is:
Notice: Undefined property: stdClass::$listitemid in C:\xampp\htdocs\joomla30\administrator\components\com_visforms\helpers\html\visforms.php on line 505 Notice: Undefined property: stdClass::$listitemvalue in C:\xampp\htdocs\joomla30\administrator\components\com_visforms\helpers\html\visforms.php on line 505 Notice: Undefined property: stdClass::$listitemlabel in C:\xampp\htdocs\joomla30\administrator\components\com_visforms\helpers\html\visforms.php on line 505Here is the code I found the $returnopts[] = array( 'id' => $option->listitemid, 'value' => $option->listitemvalue, 'label' => $option->listitemlabel, 'selected' => $selected);What is causing this problem? How can I fix this? Edited by CrazyYoda, 30 December 2014 - 05:50 PM. I've been getting this error message: Trying to get property of non-object in /application/controllers/index.php on line 37 Here is line 37 $this->view->title = $pageInfo[0]->title; any help would be much appreciated. Hey Guys.
I have a class named CoreCartFunctions. In the class there is a protected property named $menu_item_id which is initialized as null.
A method named GetMenuItemId assigns the $menu_item_id its value. I have tested it out using the following, to see if a value got returned and it did
fb($menu_item_id->GetMenuItemId(), "This is the menu id");The problem is when I access the property from a different public method in the same class it dones't return anything. fb($menu_item_id->DisplayMenuItems());It only returns something when I hard code a value to it.... Not sure why this is happening. Here is my full code. Please not the example below may have some syntax errors since I just copied and paste pieces of my code, to show a quick and dirty example. class CoreCartFunctions { protected $menu_item_id = NULL; public static $items; //Equal to the a long session string protected function GetMenuItemId() { foreach (self::$items as $menu_item_id_session) { /*********************************** Get the id of the menu item item ************************************/ $this->menu_item_id = preg_match_all('/\-(.*?)\*/',$menu_item_id_session,$match_found)?$match_found[1][0]:""; // The following line shows example of above line // $menu_item_id = "12"; public function DisplayMenuItems(){ return $this->menu_item_id; // Doesn't return Item ID } } I am trying to run a count query and faced with the error: Notice: Trying to get property of non-object in Not sure how to resolve this error in these lines:
if($result->num_rows > 0){ while($row = $result->fetch_rows()){ Code: <?php $sql = "SELECT Form_Group COUNT(Presence LIKE '/') AS Present, COUNT(Presence LIKE 'N') AS Absent, FROM 'attendance'"; $result = $conn->query($sql); ?> <?php //Fetch Data form database if($result->num_rows > 0){ while($row = $result->fetch_rows()){ ?> <tr> <td><?php echo $row['Form_Group']; ?></td> <td><?php echo $row['Present']; ?></td> <td><?php echo $row['Absent']; ?></td> </tr> <?php } } else { ?> <tr> <th colspan="6">There's No data found!!!</th> </tr> <?php } ?>
hey guys i havent done any cloneing before but what im trying to do is clone $this->_view property in my Action class and pass it to my News_Controller class so i can call the View class by a varaible and not a property....can anyone help me and give me some advise on how i should do this...i tried below but i cant get it to work...thanks alot news controller class Code: [Select] <?php class News_Controller extends Action { public function articles() { $view->title = "hello"; } } ?> action class Code: [Select] <?php class Action { protected $_request; protected $_response; public $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_view(); $view = $this->clone_view(); $view->title = "hello"; $this->_response = $response; } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_view() { $this->_view = new View; return $this; } protected function get_request() { return $this->_request; } public function clone_view() { $view = clone $this->_view; return $view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { } } } } ?> Hi, I was wondering if someone can help me, I keep getting these errors. Notice: Undefined property: stdClass::$vOptionType in /default/commonFunctions.php on line 267 That is the line from the file. if($rsOptions[$j]->vOptionType=='colour_fromcsv' || $rsOptions[$j]->vOptionType=='size_fromcsv') I was wondering if someone could tell me what it means and possible point me in the right direction on how to fix the issue. Thanks, Jordan Hello, I'm currently in the process of trying to learn php. I've been working on an issue with something I am trying to code from a book I purchased "PHP and MySQL Web Development 5th Ed." by Luke Welling and Laura Thomson. So far the book has been great, but I'm trying to figure out using MySQL and php. When I try to run this particular script for a query for a book store, I get the error: Notice: Trying to get property of non-object in C:\php-book\ch11\results.php on line 37. This is the code: Code: [Select] $query = "select * from books where ".$searchtype."like '%".$searchterm."%'"; $result = $db->query($query); $num_results = $result->num_rows; echo "<p>Number of books found: ".$num_results."</p>"; for($i=0; $i<$num_results; $i++) { $row = $result->fetch_assoc(); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br />Author: "; echo stripslashes($row['author']); echo "<br /> ISBN: "; echo stripslashes($row['isbn']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); Line 37 is specifically: $num_results = $result->num_rows; I've been bashing my head for a couple of hours here, thank you in advance to whoever can offer any help. We have a complex, json object which is multiple levels deep. We need to search for a given property/key in the entire object (not just first occurrence, but all), and if we find the property, return where in the object each property exists, so we can modify the properties value. Figure it needs to be recursive. Hi Guys Trying to get xml elements to display in a html table using the following code Code: [Select] <?php session_start(); include_once('includes/connect_inc.php'); $file="https://www.cdlvis.com/lookup/getxml?username=username&mode=test&key=password&vrm=".$_POST['veh_reg'].""; $dom=new DOMdocument(); $dom->load($file); $xml=simplexml_import_dom($dom); ?> and Code: [Select] <form name="vehicle_details" method="post" action="add_vehicle.php"> <table> <tr> <td>Registration Number:</td><td><input name="reg_num" type="text" value="<?php echo $xml->result[0]->vrm;?>" readonly="true" /></td></tr> <tr> <td>Make:</td><td><input name="make" type="text" value="<?php echo $xml->result[0]->make;?>" readonly="true" /></td></tr> <tr> <td>Model:</td><td><input name="model" type="text" value="<?php echo $xml->result[0]->model;?>" readonly="true" /></td></tr> <tr> <td>Date of Manufactu </td><td><input name="date_man" type="text" value="<?php echo $xml->result[0]->date_manufactured;?>" readonly="true" /></td></tr> <tr> <td>Date of First Registration:</td><td><input name="date_reg" type="text" value="<?php echo $xml->result[0]->first_registered;?>" readonly="true" /></td></tr> <tr> <td>Colour:</td><td><input name="colour" type="text" value="<?php echo $xml->result[0]->colour;?>" readonly="true" /></td></tr> <tr> <td>Body Style:</td><td><input name="body" type="text" value="<?php echo $xml->result[0]->body;?>" readonly="true" /></td></tr> <tr> <td>Number of Doors:</td><td><input name="doors" type="text" value="<?php echo $xml->result[0]->doors;?>" readonly="true" /></td></tr> <tr> <td>Engine Size:</td><td><input name="engine_size" type="text" value="<?php echo $xml->result[0]->engine_size;?>" readonly="true" /></td></tr> <tr> <td>Fuel Type:</td><td><input name="fuel_type" type="text" value="<?php echo $xml->result[0]->fuel;?>" readonly="true" /></td></tr> <tr> <td>Gearbox Type:</td><td><input name="gearbox" type="text" value="<?php echo $xml->result[0]->gearbox_type;?>" readonly="true" /></td></tr> <tr> <td>Previous Keepers:</td><td><input name="keepers" type="text" value="<?php echo $xml->result[0]->previous_keepers;?>" readonly="true" /></td></tr> <tr> <td>BHP:</td><td><input name="bhp" type="text" value="<?php echo $xml->result[0]->smmt_power_bhp;?>" readonly="true" /></td></tr> <tr> <td>Emissions:</td><td><input name="co2" type="text" value="<?php echo $xml->result[0]->smmt_co2;?>" readonly="true" /></td></tr> <tr> <td><input name="try_again" type="button" value="Try Again" /></td><td><input name="submit" type="submit" value="Next Stage" /></td></tr> </table> </form> What have I done wrong? Hey Guys. I have a shopping cart script that loops through the shopping cart session array and assigns values to the property of a class. For some weird reason the subtotal property only works when I use the self keyword. If I use the $this-> instance variable the sub total does not get assigned the subtoal price. Its just NULL.
Does anyone have any suggestions as to why it may not be working.
Below is a quick copy and paste of my code. Please be aware that some there may be some syntax mistakes as a result to copying and pasting part of my code that is relevant to this issue. Thanks!
class CoreCartFunctions { protected static $subtotal; protected $menu_item_price = NULL; public function GetMenuItem() { //self:items is the cart session array that is initilized in a construct method //Assign the values for each cart array foreach (self::$items as $menu_item_id_session) { $this->menu_item_price = getItems($this->menu_item_id,"menu_item_price")*$this->item_qty; self::$subtotal += $this->menu_item_price; //Does not work with the following ---> $this->subtotal += $this->menu_item_price; } } For example: class People{ var $them = array(); function groupPeople(){ foreach($this->them as $him){ echo $him.", "; } } } $people = new People; $people->them = array('Harry','Todd'); $people->them = array('Tom','Jerry'); $people->groupPeople(); // result: Tom, Jerry, I think this code is working. However, I need to merge those array above, array('Harry','Todd') and array('Tom','Jerry') So I can get array('Harry','Todd','Tom','Jerry') and a list of names as a result. Maybe I should use array_merge, but how? A little help would be appreciated. Thank you in advanced, ayok Keep getting this error from line 19 (Notice: Trying to get property of non-object in /clientdata/zeus-dynamic-1/s/o/blahblah/www/tyson/onion.php on line 18)... have no idea how to get rid of it. Do I have to use isset? If so.. where??? (obviously I've replaced site address with website) Code: [Select] include('simple_html_dom.php'); $story = array(); getArticles('website'); function getArticles($page) { global $story, $desc, $read; $html = new simple_html_dom(); $html->load_file($page); $items = $html->find('div[id=story_content]'); foreach($items as $post) { $story[] = array($post->children(0)->plaintext, $post->children(2)->next_sibling()->innertext, $post->children(4)->innertext); } } $i = 0; foreach($story as $item) { $syurl = str_replace('href="', 'href="http://website', $item[2]); echo '<p class="storytitle">' . $item[0] . '</p>'; echo '<p class="storyexcerpt">' . $item[1] . '</p>'; echo '<p class="storyread">' . $syurl . '</p>'; if (++$i == 3) break; } Any ideas? This line is causing the issue: $story[] = array($post->children(0)->plaintext, $post->children(2)->next_sibling()->innertext, $post->children(4)->innertext); Likewise, it does post the 3 storys below the 2 error lines...? I am using the following code
foreach ($fbdata->data as $post ) { $posts .= '<li>'; $posts .= '<p>' . $post->message . '</p>'; $posts .= date('d-M-y', strtotime($post->created_time)); $posts .= '</li>'; } and if the message propeerty doesn't exist I get the message above. Any ideas on the best way to fix this? error Notice: Undefined property: stdClass::$post_url in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 133 Notice: Undefined property: stdClass::$post_title in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 133 Notice: Undefined property: stdClass::$post_date in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 137 Notice: Undefined variable: fb in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 138 Notice: Undefined variable: tw in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 140 Posted Posted on | Facebook Facebook Twitter Twitter Notice: Undefined property: stdClass::$post_content in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 153 Notice: Undefined property: stdClass::$post_url in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 154 http://www.socialnewsoffice.com/blog_posts?start=0&api_key=b5cbd66dca99c49d1a6c3d ive used this a my json Code: [Select] //check if you have curl loaded if(!function_exists("curl_init")) die("cURL extension is not installed"); function Social_News_Office($action, $api_key){ // jSON URL which should be requested $json_url = $action.'&api_key='.api_key.''; // Initializing curl $ch = curl_init( $json_url ); // Configuring curl options $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: application/json') , ); // Setting curl options curl_setopt_array( $ch, $options ); // Getting results return $result = json_decode(curl_exec($ch)); // Getting jSON result string } $blog_posts = Social_News_Office('http://www.socialnewsoffice.com/blog_posts?start=2&display=6', api_key); foreach($blog_posts as $post) { echo '<!--START OF POST--> <div class="post"> <h2 class="post-heading"><a href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/">' . strip_tags($post->post_title) . '</a></h2> <!--START OF BLOG INFO--> <p class="meta"> <img alt="Posted" class="meta-img" src="http://www.socialnewsoffice.com/blog-images/time.png"> Posted on ' . $post->post_date . ' | <a target="_blank" href="'.$fb.'" class="socialusers icon Facebook"> <img alt="Facebook" src="http://www.socialnewsoffice.com/blog-images/facebook.png"> Facebook </a> <a target="_blank" href="http://twitter.com/#!/'.$tw.'" class="socialusers icon Twitter"> <img src="http://www.socialnewsoffice.com/blog-images/twitter.png" alt="Twitter" align="baseline"> Twitter </a> </p> <!--START OF POST CONTENT--> <div class="post-content">'; if(!empty($post->article_img)){ echo '<a href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/"> <img alt="' . strip_tags($post->post_title) . '" class="post-thumbnail" src="' . BLOG_BASE_URL . 'sno-blog/thumbnail.php?file='.$post->article_img.'&width=240&height=160" title="' . strip_tags($post->post_title) . '"></a>'; } echo '<p>' . $post_content = substr(strip_tags($post->post_content,'<p><br><a>'),0,266).'...' . '</p> <a class="read-more" href="' . BLOG_BASE_URL . 'article/' . $post->post_url . '/">Continue reading</a> <div class="clear"></div> </div><!--END OF POST CONTENT--> </div><!--END OF POST-->'; } I want to save class property values and want to write these in the database after being called from another function. Code: [Select] class model{ public $dbh; public $user_arr=array('username','password','email','location','interest','homepage'); public function insert_data() { $sql = "INSERT INTO account VALUES ('" .$user_info['username']."','".$user_info['password'] ."','".$user_info['email']."', 'user','".$user_info['location']."','".$user_info['interests'] ."','".$user_info['homepage']."')"; //if(isset($data)) echo $sql; } public function data_approoved($user){ //$user_info = new array(); $user_arr['username'] = $user['username']; $user_arr['password'] = $user['password']; $user_arr['email'] = $user['email']; $user_arr['location'] = $user['location']; $user_info['interests'] = $user['interests']; $user_info['homepage'] = $user['homepage']; Model::insert_data(); } } }//class ended The approoved_data function is supposed to set the values of $user_info array which should be later on stored in database. Please somebody help me. |