-2

I try to show the counter of messages at the navbar but i thing i do in incorrect way , i try to google about the error but can not find way to solve this error How do i insert the $rec_count variable in correct way?

Fatal error : Constant expression contains invalid operations in C:\Program Files\Ampps\www\wizjobs2022v4\helpers\Menu.php on line 158 The error is in this section

array(
        'path' => '', 
        'label' => $rec_count, 
        'icon' => '<i class="fa fa-bell "></i>'

    )
<?php
/**
* Menu Items
* All Project Menu
* @category  Menu List
*/

$comp_model = new SharedController;

$rec_count = $comp_model->getcount_messages();
class Menu{


        public static $navbarsideleft = array(
    array(
        'path' => 'home', 
        'label' => 'Home', 
        'icon' => '<i class="fa fa-home "></i>'
    ),
    
    array(
        'path' => 'jobs', 
        'label' => 'Jobs', 
        'icon' => '<i class="fa fa-briefcase "></i>'
    ),
    
    array(
        'path' => 'resume', 
        'label' => 'CVs', 
        'icon' => '<i class="fa fa-file-text-o "></i>'
    ),
    
    array(
        'path' => '', 
        'label' => 'Blogs', 
        'icon' => '<i class="fa fa-bold "></i>',
'submenu' => array(
    array(
        'path' => 'blogs/Index', 
        'label' => 'Blogs', 
        'icon' => '<i class="fa fa-bold "></i>'
    ),
    
    array(
        'path' => 'blogcomments', 
        'label' => 'Blog Comments', 
        'icon' => '',
'submenu' => array(
    array(
        'path' => 'blogcomments/Index', 
        'label' => 'Blog Comments', 
        'icon' => ''
    )
)
    ),
    
    array(
        'path' => 'blogs/pending_blogs', 
        'label' => 'Pending Blogs', 
        'icon' => ''
    ),
    
    array(
        'path' => 'subdomainblogs/subblog', 
        'label' => 'Sub Domain Blogs', 
        'icon' => '<i class="fa fa-bold "></i>'
    ),
    
    array(
        'path' => 'subdomainblogs/add', 
        'label' => 'Sub Domain Blogs Add', 
        'icon' => '<i class="fa fa-plus-square-o "></i>'
    ),
    
    array(
        'path' => 'subdomainblogs/subblog_pending', 
        'label' => 'Sub Domains Blogs Pending', 
        'icon' => ''
    )
)
    ),
    
    array(
        'path' => 'categories', 
        'label' => 'Categories', 
        'icon' => '<i class="fa fa-tags "></i>'
    ),
    
    array(
        'path' => 'messages', 
        'label' => 'Messages', 
        'icon' => '<i class="fa fa-envelope "></i>'
    ),
    
    array(
        'path' => 'wiz_chain', 
        'label' => 'Wiz Chain', 
        'icon' => '<i class="fa fa-area-chart "></i>'
    ),
    
    array(
        'path' => 'sites', 
        'label' => 'Sites', 
        'icon' => '<i class="fa fa-link "></i>'
    ),
    
    array(
        'path' => 'images', 
        'label' => 'Images', 
        'icon' => '<i class="fa fa-image "></i>'
    ),
    
    array(
        'path' => 'how_to', 
        'label' => 'How To', 
        'icon' => '<i class="fa fa-book "></i>'
    ),
    
    array(
        'path' => 'users', 
        'label' => 'Users', 
        'icon' => '<i class="fa fa-users "></i>'
    ),
    
    array(
        'path' => 'guia', 
        'label' => 'Guia', 
        'icon' => ''
    ),
    
    array(
        'path' => 'tableprices', 
        'label' => 'Tableprices', 
        'icon' => ''
    )
);
    
        public static $navbartopleft = array(
    array(
        'path' => 'jobs/add', 
        'label' => 'Add New Job', 
        'icon' => '<i class="fa fa-plus-square-o "></i>'
    ),
    
    array(
        'path' => 'categories/add', 
        'label' => 'Add New Category', 
        'icon' => '<i class="fa fa-plus-square-o "></i>'
    ),
    
    array(
        'path' => 'blogs/add', 
        'label' => 'Add New Blog', 
        'icon' => '<i class="fa fa-plus-square-o "></i>'
    )
);
    
        public static $navbartopright = array(
    array(
        'path' => 'online/Index', 
        'label' => 'Online', 
        'icon' => '<i class="fa fa-globe "></i>'
    ),
    
    array(
        'path' => 'users/scores', 
        'label' => 'Top 10 users', 
        'icon' => '<i class="icon-diamond "></i>'
    ),
    
    array(
        'path' => 'workshop', 
        'label' => 'Workshop', 
        'icon' => '<i class="fa fa-shopping-basket "></i>',
'submenu' => array(
    array(
        'path' => 'workshop/Index', 
        'label' => 'Workshop', 
        'icon' => '<i class="fa fa-shopping-basket "></i>'
    ),
    
    array(
        'path' => 'workshop/pending_workshoops', 
        'label' => 'Pending Workshoops', 
        'icon' => '<i class="fa fa-shopping-basket "></i>'
    )
)
    ),
    
    array(
        'path' => '', 
        'label' => $rec_count, 
        'icon' => '<i class="fa fa-bell "></i>'
        
    )
);
    


        public static $job_type = array(
    array(
        "value" => "Aviation", 
        "label" => "Aviation", 
    ),
    array(
        "value" => "Arts", 
        "label" => "Arts", 
    ),
    array(
        "value" => "Business", 
        "label" => "Business", 
    ),
    array(
        "value" => "Agro", 
        "label" => "Agro", 
    ),
    array(
        "value" => "Forest maintenance", 
        "label" => "Forest maintenance", 
    ),
    array(
        "value" => "Garder Care", 
        "label" => "Garder Care", 
    ),
    array(
        "value" => "Painter", 
        "label" => "Painter", 
    ),
    array(
        "value" => "Plumber", 
        "label" => "Plumber", 
    ),
    array(
        "value" => "Education", 
        "label" => "Education", 
    ),
    array(
        "value" => "Law Enforcement", 
        "label" => "Law Enforcement", 
    ),
    array(
        "value" => "Media", 
        "label" => "Media", 
    ),
    array(
        "value" => "Medical", 
        "label" => "Medical", 
    ),
    array(
        "value" => "Service", 
        "label" => "Service", 
    ),
    array(
        "value" => "Technology", 
        "label" => "Technology", 
    ),
    array(
        "value" => "Social Media Manager", 
        "label" => "Social Media Manager", 
    ),
    array(
        "value" => "Online Tutor", 
        "label" => "Online Tutor", 
    ),
    array(
        "value" => "Bookkeeper", 
        "label" => "Bookkeeper", 
    ),
    array(
        "value" => "HouseSiting", 
        "label" => "HouseSiting", 
    ),
    array(
        "value" => "DogKeeper", 
        "label" => "DogKeeper", 
    ),
    array(
        "value" => "Personal Trainer", 
        "label" => "Personal Trainer", 
    ),
    array(
        "value" => "Online Beauty Advisor", 
        "label" => "Online Beauty Advisor", 
    ),
    array(
        "value" => "Online Recruiter", 
        "label" => "Online Recruiter", 
    ),
    array(
        "value" => "Email Marketer", 
        "label" => "Email Marketer", 
    ),
    array(
        "value" => "Freelance Writer", 
        "label" => "Freelance Writer", 
    ),
    array(
        "value" => "Proofreader", 
        "label" => "Proofreader", 
    ),
    array(
        "value" => "Website Designer", 
        "label" => "Website Designer", 
    ),
    array(
        "value" => "Instagram Influencer", 
        "label" => "Instagram Influencer", 
    ),
    array(
        "value" => "SEO Expert", 
        "label" => "SEO Expert", 
    ),
    array(
        "value" => "Facebook Ads Specialist", 
        "label" => "Facebook Ads Specialist", 
    ),
    array(
        "value" => "Graphic Designer", 
        "label" => "Graphic Designer", 
    ),
    array(
        "value" => "Voiceover Artist", 
        "label" => "Voiceover Artist", 
    ),
    array(
        "value" => "Stock Photographer", 
        "label" => "Stock Photographer", 
    ),
    array(
        "value" => "Data Entry Worker", 
        "label" => "Data Entry Worker", 
    ),
    array(
        "value" => "Virtual Assistant", 
        "label" => "Virtual Assistant", 
    ),
    array(
        "value" => "Customer Service Rep", 
        "label" => "Customer Service Rep", 
    ),
    array(
        "value" => "Music Reviewer", 
        "label" => "Music Reviewer", 
    ),
    array(
        "value" => "Transcriptionist", 
        "label" => "Transcriptionist", 
    ),
    array(
        "value" => "Chat Agent", 
        "label" => "Chat Agent", 
    ),
    array(
        "value" => "Website Tester", 
        "label" => "Website Tester", 
    ),
    array(
        "value" => "Online Moderator", 
        "label" => "Online Moderator", 
    ),
    array(
        "value" => "Micro Job", 
        "label" => "Micro Job", 
    ),);
    
        public static $user_type = array(
    array(
        "value" => "Administrator", 
        "label" => "Administrator", 
    ),
    array(
        "value" => "Jobseeker", 
        "label" => "Jobseeker", 
    ),
    array(
        "value" => "Employeer", 
        "label" => "Employeer", 
    ),);
    
        public static $account_status = array(
    array(
        "value" => "Active", 
        "label" => "Active", 
    ),
    array(
        "value" => "Pending", 
        "label" => "Pending", 
    ),
    array(
        "value" => "Blocked", 
        "label" => "Blocked", 
    ),);
    
        public static $Department = array(
    array(
        "value" => "Accounting and Banking", 
        "label" => "Accounting and Banking", 
    ),
    array(
        "value" => "Construction", 
        "label" => "Construction", 
    ),
    array(
        "value" => "Faishon and Style", 
        "label" => "Faishon and Style", 
    ),
    array(
        "value" => "Food and Restaurents", 
        "label" => "Food and Restaurents", 
    ),
    array(
        "value" => "Healthcare", 
        "label" => "Healthcare", 
    ),
    array(
        "value" => "Retail and Sales", 
        "label" => "Retail and Sales", 
    ),
    array(
        "value" => "Agro", 
        "label" => "Agro", 
    ),
    array(
        "value" => "Animals care", 
        "label" => "Animals care", 
    ),
    array(
        "value" => "House Siting", 
        "label" => "House Siting", 
    ),
    array(
        "value" => "Technology", 
        "label" => "Technology", 
    ),
    array(
        "value" => "Forest Care", 
        "label" => "Forest Care", 
    ),
    array(
        "value" => "Garden Care", 
        "label" => "Garden Care", 
    ),);
    
        public static $state = array(
    array(
        "value" => "active", 
        "label" => "Active", 
    ),
    array(
        "value" => "pending", 
        "label" => "Pending", 
    ),
    array(
        "value" => "block", 
        "label" => "Block", 
    ),);
    
        public static $status = array(
    array(
        "value" => "pending", 
        "label" => "Pending", 
    ),
    array(
        "value" => "active", 
        "label" => "Active", 
    ),
    array(
        "value" => "block", 
        "label" => "Block", 
    ),);
    
        public static $produtos = array(
    array(
        "value" => "job payment", 
        "label" => "Job Payment", 
    ),
    array(
        "value" => "workshop payment", 
        "label" => "Workshop Payment", 
    ),
    array(
        "value" => "blogs payment", 
        "label" => "Blogs Payment", 
    ),);
    
        public static $metodo = array(
    array(
        "value" => "bank transfer", 
        "label" => "Bank Transfer", 
    ),
    array(
        "value" => "pay pal", 
        "label" => "Pay Pal", 
    ),);
    
        public static $statusdopagamento = array(
    array(
        "value" => "pending", 
        "label" => "Pending", 
    ),
    array(
        "value" => "payd", 
        "label" => "Payd", 
    ),);
    
}
  • It is the `$rec_count` on line 192 that spoils the soup. – KIKO Software Nov 03 '22 at 10:04
  • @KIKOSoftware yes its the one – roffy miranda Nov 03 '22 at 10:04
  • Ah, haha, you do say that in your question, sorry... – KIKO Software Nov 03 '22 at 10:05
  • @KIKOSoftware just edited to add that info – roffy miranda Nov 03 '22 at 10:08
  • Anyway, you cannot use a variable inside a constant expression. But now I am simply repeating the error message. So what you need to replace this with something that can accept something dynamic. A method, for instance. – KIKO Software Nov 03 '22 at 10:09
  • Just a tip, for the next time you ask a question. We don't need all 500+ lines of code, a [minimal example](https://stackoverflow.com/help/minimal-reproducible-example) would have sufficed. – KIKO Software Nov 03 '22 at 10:11
  • @KIKOSoftware can you please share any refenrence how to do the method – roffy miranda Nov 03 '22 at 10:17
  • 1
    Yes, see; [Classes and Objects](https://www.php.net/manual/en/language.oop5.php). A method is part of a class. It's basically a function inside your class. You need to study how classes and objects work, and what the code you're writing actually does. – KIKO Software Nov 03 '22 at 10:22
  • @KIKOSoftware as right. It's a problem of understanding classes and objects. [Learn Class in PHP](https://dzone.com/articles/learn-php-how-write-class-php) – Juan Nov 03 '22 at 10:28

1 Answers1

0

You cannot use expressions (well, some are allowed, but very few) for class variable initialization. You have to use literal values.

If you want to initialize the array with dynamic values, use a constructor instead.

See also: PHP Error : Fatal error: Constant expression contains invalid operations

fbitterlich
  • 882
  • 7
  • 24