php - Reuse instance of class -


i thinking missing out on oop php.

i developing plugin wordpress have class declaration book:

<?php class wpbook{     private $title;     function settitle($_title){         $this->title = $_title;     }     function gettitle(){         return $this->title;     } } ?>  add_action( 'hookone', 'function_do_stuff'); add_action( 'hookafter_hookone', 'function_do_more_stuff'); function function_do_stuff(){      //some more stuff     $newbook = new wpbook;     $title = $newbook->settitle ='titlea';     echo $title; //echos 'titlea';     // function_do_more_stuff($title); not work because     // function called on hookafter_hookone }  function function_do_more_stuff(){     // here want access $title function_do_stuff();     // not know how. } 

now want able access title of book do_stuff() function function do_more_stuff().

the problem can't use returns form do_stuff() do_more_stuff(), because do_more_stuff() called on action-hook.

so problem not know how access title of same product 2 different functions passing 1 variable 1 function function.

there obscure in question, because example uses custom hooks hookone , hookafter_hookone.

this important because, depending way hook called, able use class object reference.

in case of basic call <?php do_action('hookafter_hookone'); ?> stuck in present case.

but if hook called <?php do_action_ref_array('hookafter_hookone', array(&$newbook)); ?> see doc. here can access directly referenced object this:

<?php  function function_do_more_stuff(&$newbook){    newbook->settitle ='titleb'; } 

another way globalize object outside of functions, it's maybe not expected effect.

hope helps.


Comments

Popular posts from this blog

How can we post XML strings along with text strings in iOS -

How to run C# code using mono without Xamarin in Android? -

c# - cefsharp app remember password option -