Tsalagi Posted September 11, 2010 Share Posted September 11, 2010 I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; } Quote Link to comment https://forums.phpfreaks.com/topic/213161-oop-variables-or-array-how-to-return-variable/ Share on other sites More sharing options...
KevinM1 Posted September 11, 2010 Share Posted September 11, 2010 The '->' is the object-to-member operator, with a 'member' being either a field in the object (object data like a string, integer, etc.) or method of the object (function that acts on the object itself). So, for something like ct->title, 'title' is a field of the ct object. In the case of this current_theme_info() function, it's assigning all of these array values to particular fields within the ct object. After this function is run, if you wanted to output the title, all you'd need to do would be: echo ct->title; Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/213161-oop-variables-or-array-how-to-return-variable/#findComment-1110002 Share on other sites More sharing options...
Tsalagi Posted September 11, 2010 Author Share Posted September 11, 2010 Thanks. That works if I want to use it outside of another function, but when I want to use it as a parameter it doesn't work. I tried putting $ct into an array which I can use print_r to view it but I don't know how to target $ct->title as a $key $value pair and then pass that into a variable using a foreach statement. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/213161-oop-variables-or-array-how-to-return-variable/#findComment-1110051 Share on other sites More sharing options...
KevinM1 Posted September 12, 2010 Share Posted September 12, 2010 Thanks. That works if I want to use it outside of another function, but when I want to use it as a parameter it doesn't work. I tried putting $ct into an array which I can use print_r to view it but I don't know how to target $ct->title as a $key $value pair and then pass that into a variable using a foreach statement. Any suggestions? You can't use an object member like that unless it's an array itself. You can simply use the title as a function parameter: function someFunction($arg) { // do something } someFunction($ct->title); Quote Link to comment https://forums.phpfreaks.com/topic/213161-oop-variables-or-array-how-to-return-variable/#findComment-1110073 Share on other sites More sharing options...
Tsalagi Posted September 12, 2010 Author Share Posted September 12, 2010 Okay. I'll have to re-plan this one. Thanks a bunch! Thanks for the link to post rules too. Quote Link to comment https://forums.phpfreaks.com/topic/213161-oop-variables-or-array-how-to-return-variable/#findComment-1110078 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.