tommytx Posted February 3, 2015 Share Posted February 3, 2015 Can someone help me understand what this type of php is... classes etc.. <?php // item 1 ***** get the excerpt ***** $excerpt = IDX_Plus::get_data('excerpt'); echo "echo-1 excerpt = $excerpt<br><br>"; // item 2 ***** set the excerpt *********** IDX_Plus::set_data( 'excerpt', $excerpt); // item 3 ***** get the excerpt again ******* $excerpt = IDX_Plus::get_data('excerpt'); echo "echo-2 excerpt = $excerpt<br><br>"; // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // item 4 now shorten the excerpt // ***** shorten the excerpt *********** $short_excerpt = wp_trim_words($excerpt,10); echo "echo-3 short_excerpt = $short_excerpt<br><br>"; // item 5 ***** set short_excerpt *********** IDX_Plus::set_data( 'short_excerpt', $short_excerpt); // item 6 ***** get short_excerpt again ******* $short_excerpt = IDX_Plus::get_data('short_excerpt'); echo "echo-4 short_excerpt = $short_excerpt<br><br>"; ?> I can't get it to work so if someone can point me to where I can find info on how this type of php works I will be forever grateful...it pulls data form a cache storage on the web and tries to shorten the output and write the short line back to a new variable..The results look like below: Resulting output: ***************** echo-1 excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and bright, this 'one owner' home boasts original hardwood floors and 'classic' 1953 tile in kitchen and bath. The freshly painted interior, new kitchen and bathroom faucets, new vinyl floor in bath, and new water heater, make this home move-in ready. Large 'pool size' fenced yard for the kids. Perfect for your buyers who love the classic look of the 50's, or for those looking to remodel and expand. echo-2 excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and bright, this 'one owner' home boasts original hardwood floors and 'classic' 1953 tile in kitchen and bath. The freshly painted interior, new kitchen and bathroom faucets, new vinyl floor in bath, and new water heater, make this home move-in ready. Large 'pool size' fenced yard for the kids. Perfect for your buyers who love the classic look of the 50's, or for those looking to remodel and expand. echo-3 short_excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and… echo-4 short_excerpt = the short line does not appear so it must not have saved... Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 3, 2015 Share Posted February 3, 2015 Perhaps the following will help: http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php It also looks like there is a WordPress function mixed in there: http://codex.wordpress.org/Function_Reference/wp_trim_words Quote Link to comment Share on other sites More sharing options...
Solution scootstah Posted February 3, 2015 Solution Share Posted February 3, 2015 Assuming you're talking about this syntax: IDX_Plus::get_data('excerpt'); There are two ways to use classes. You can either instantiate them, or you can call static methods. When you instantiate the class, you create an object variable of that class type. You can then call the class methods, set properties, etc. This object variable will hold the state of the class. When you use static methods, you just call the method directly without instantiating the class or creating an object. Here is how that works in code. Instantiated: class HelloWorld { public function print() { echo 'Hello World!'; } } $helloWorld = new HelloWorld(); $helloWorld->print();Static method:class HelloWorld { public static function print() { echo 'Hello World!'; } } HelloWorld::print();Normally static methods should be avoided. They don't typically utilize good application design. Static methods are typically used with helper classes, where you might not need to instantiate it... you just want to run a quick method. A lot of times though, they're also used to (badly) avoid the need for dependency injection, which makes code really terrible. Quote Link to comment Share on other sites More sharing options...
tommytx Posted February 3, 2015 Author Share Posted February 3, 2015 Thank you all for all your valuable suggestions and referral URLs that I can see are right on the money.. I see a lot to study to see if I can make this simple item work for me..Thanks cyberRobot.. good call on WP.. this php does run on a wordpress site.. In the references given I can see some of my format like "return self::$my_static;". Right on Scootash.. exactly what I am trying to do is understand this syntax: IDX_Plus::get_data('excerpt'); So Scootash: base on what I have above all this IDX_Plus stuff may be a class then correct?class IDX_Plus{public static function print(){echo 'Hello World!';}}IDX_Plus::print(); So I really appreciate all the little tidbits.. they are helping me significantly... i know basic PHP prettty good but lousy with classes and would love to learn more about it.. and will use this to study in detail more about these specific examples..So please anyone reading this throw in any snippet or examples I could look at that use the syntax even close to this IDX_Plus::get_data('excerpt'); I was so happy today when I saw my post not thrown out as I realize this is sorta an odd question with no real answer but a lot of little remarks that help a lot.. So can I expound a little and maybe others will see what I am trying to do and can offer thoughts or ideas..1. The way i understand it is Item 1 at the top.. is getting some stored data from somewhere I suppose cache storage or someplace else and placing it in variable $excerpt and we are success full as the echo at echo1 shows the data taken from storage.2. Item 2 attempts to re-store the very same data to same place it came from... but I doubt it was successful since if I try to store any other data there it does not change..3. Item 3 attempts to get the data again to see if it stored.. but i think it just got another copy.. since when I tried to store something different there it failed.4. Item 4 uses a wordpress command to shorten the data that was grabbed in item 1.. and it is successful based on echo 3.5. item 5 attempts to write the short data over a new variable.. i think that may be the problem.. I have to set up the variable before it can be written to.. 6. Item 6 is an attempt to read the new varialbe but fails.... so was there some prep work that was needed before I could write to that varialbe... I really appreciate your patience and i will study all the references to the nth degree.. so if anyone has any other thoughs or references please help... I know you all want to say.. get a good OOP book and go from cover to cover... I would if I had time.. but I am hoping to lean enough here to be dangerous..Thank you all soooooo much... Quote Link to comment Share on other sites More sharing options...
scootstah Posted February 4, 2015 Share Posted February 4, 2015 So I really appreciate all the little tidbits.. they are helping me significantly... i know basic PHP prettty good but lousy with classes and would love to learn more about it http://www.amazon.com/Objects-Patterns-Practice-Matt-Zandstra/dp/1430260319 Buy this book then. It's very good. 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.