Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:05:54+00:00 2026-06-03T14:05:54+00:00

I am new to OOP and have a class, inside this class I am

  • 0

I am new to OOP and have a class, inside this class I am trying to run

foreach($categories as $category) { 
                public function beam_channels_setting.$category->name()
                {
                    echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";

                        } 
        }

However I keep getting this error: unexpected T_FOREACH

I understand that this is because it is looking for a function, but I do not know how to overcome this, would I put it all within another function?

class

Class BEAM_Options {

    public $options;
    public $categorielist;

    public function __construct()
    {
        $args = array(
            'type'                     => 'post',
            'orderby'                  => 'name',
            'order'                    => 'ASC',
            'hide_empty'               => 0, //<--IMPORTANT!!
            'hierarchical'             => 1,
            'taxonomy'                 => 'category',
            'pad_counts'               => false );
        $categories = get_categories($args);
        $this->options = get_option('beam_plugin_options');
        $this->register_settings_and_fields();
    }

    public function add_menu_page()
    {
        add_options_page('Ad Management', 'Ad Management', 'administrator', __FILE__, array('BEAM_Options', 'display_options_page'));
    }

    public function display_options_page()
    {
        ?>

        <div class="wrap">
            <?php screen_icon(); ?>
            <h2> Ad Management</h2>
            <form method="post" action="options.php">
                <?php settings_fields('beam_plugin_options'); ?>
                <?php do_settings_sections(__FILE__); ?>


                <p class="submit">
                    <input name="submit" type="submit" class="button-primary" value="Save Changes" />
                </p>
            </form>
        </div>
        <?php
    }

    public function register_settings_and_fields()
    {
        register_setting('beam_plugin_options', 'beam_plugin_options');
        add_settings_section('beam_main_section', 'Settings', array($this, 'beam_main_section_cb'), __FILE__); //id, title, section, callback, page
        add_settings_field('beam_refresh_time_truth','Do you want the Advertisements to Auto-Refresh?', array($this,'beam_refresh_time_truth_setting'), __FILE__, 'beam_main_section');
        add_settings_field('beam_refresh_time','Refresh Time(seconds)', array($this,'beam_refresh_time_setting'), __FILE__, 'beam_main_section');
        $args = array(
            'type'                     => 'post',
            'orderby'                  => 'name',
            'order'                    => 'ASC',
            'hide_empty'               => 0, //<--IMPORTANT!!
            'hierarchical'             => 1,
            'taxonomy'                 => 'category',
            'pad_counts'               => false );
            $categories = get_categories($args);
          foreach($categories as $category) { 
        add_settings_field("beam_channels.$category->name","$category->name", array($this,"beam_channels_setting.$category->name"), __FILE__, 'beam_main_section');
        }
    }


          foreach($categories as $category) { 
                public function beam_channels_setting.$category->name()
                {
                    echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";

                        } 
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:05:57+00:00Added an answer on June 3, 2026 at 2:05 pm
    public function beam_channels_setting.$category->name() {..}
    

    will not works. If you want to declare your function, it must be outter of your loop.

    public function functionName(){
         ...
    }
    

    and then use it in your loop:

    foreach(...){
      $this->functionName();
    }
    

    in your class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to OOP with Perl, and just had a quick question. I have this
I'm pretty new to OOP, so any help is appreciated. I have a class
We have a class like this: class LogAnalyzer { protected IExtensionManager manager; public LogAnalyzer()
I am new to OOP and I have been working on this example but
Consider this example (typical in OOP books): I have an Animal class, where each
I'm new to Java, but have some OOP experience with ActionScript 3, so I'm
I'm new to the OOP paradigm, so there's probably a simple explanation for this
I'm very new to OOP, and in the program I'm working on, I have
I'm very new to OOP and am trying my hardest to keep things strictly
I have a class called PurchaseOrderItem public class PurchaseOrderItem { public Int64 PONumber {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.