Skip to main content
Post Reopened by Jamal
added 6 characters in body
Source Link

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter:

echo adminTemplate::load()->wrapSidebars(myClassadminTemplate::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way.

  1. Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  2. Besides that, is there a more elegant code structure to accomplish the same "task"?

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter:

echo adminTemplate::load()->wrapSidebars(myClass::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way.

  1. Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  2. Besides that, is there a more elegant code structure to accomplish the same "task"?

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter:

echo adminTemplate::load()->wrapSidebars(adminTemplate::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way.

  1. Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  2. Besides that, is there a more elegant code structure to accomplish the same "task"?
deleted 55 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter.

The way I currently do that, is:

echo adminTemplate::load()->wrapSidebars(myClass::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way... So my questions:

  • There is a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  • Besides that, there is a more elegant code structure to accomplish the same "task"?
  1. Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  2. Besides that, is there a more elegant code structure to accomplish the same "task"?

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter.

The way I currently do that, is:

echo adminTemplate::load()->wrapSidebars(myClass::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way... So my questions:

  • There is a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  • Besides that, there is a more elegant code structure to accomplish the same "task"?

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start(); echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter:

echo adminTemplate::load()->wrapSidebars(myClass::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way.

  1. Is there a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  2. Besides that, is there a more elegant code structure to accomplish the same "task"?
Changed pseudo-code to real code
Source Link

Calling a method outside class statically, passing other methodmethod's output as parameter

I have a class like this class:

class myClassadminTemplate { public static function load() { return new self(); } public function myMethod1 sidebarGuide() { return 'content'; // Very long html markup } public function myMethod2 wrapSidebars($content) { returnob_start();  'modified '. echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call myMethod2wrapSidebars using myMethod1sidebarGuide's output as parameter.

The way I currently do that, is:

echo myClassadminTemplate::load()->myMethod2>wrapSidebars(myClass::load()->myMethod1>sidebarGuide()); //modified content 

It works, but I'm pretty confident there is a more appropriate way... So my questions:

  • There is a proper way of passing methodsmethods'output as other method's parameter in a class loaded "statically"?
  • Besides that, there is a more elegant code structure to accomplish the same "task"?

Calling a method outside class statically, passing other method as parameter

I have a class like this:

class myClass { public static function load() { return new self(); } public function myMethod1 () { return 'content'; } public function myMethod2 ($content) { return 'modified '.$content; } } 

Somewhere in my script, I have to call myMethod2 using myMethod1's output as parameter.

The way I currently do that, is:

echo myClass::load()->myMethod2(myClass::load()->myMethod1()); //modified content 

It works, but I'm pretty confident there is a more appropriate way... So my questions:

  • There is a proper way of passing methods as other method's parameter in a class loaded "statically"?
  • Besides that, there is a more elegant code structure to accomplish the same "task"?

Calling a method outside class statically, passing other method's output as parameter

I have this class:

class adminTemplate { public static function load() { return new self(); } public function sidebarGuide() { return 'content'; // Very long html markup } public function wrapSidebars($content) { ob_start();   echo "<div class='sidebar wrapper'>"; echo $content; echo "</div>"; $output = ob_get_contents(); ob_end_clean(); return $output; } // Other methods here } 

Somewhere in my script, I have to call wrapSidebars using sidebarGuide's output as parameter.

The way I currently do that, is:

echo adminTemplate::load()->wrapSidebars(myClass::load()->sidebarGuide()); 

It works, but I'm pretty confident there is a more appropriate way... So my questions:

  • There is a proper way of passing methods'output as other method's parameter in a class loaded "statically"?
  • Besides that, there is a more elegant code structure to accomplish the same "task"?
Post Closed as "Not suitable for this site" by Jamal
deleted 11 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
Loading