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 7875561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:00:13+00:00 2026-06-03T03:00:13+00:00

Ok, this is very unexpected and it annoys me. I have function called default()

  • 0

Ok, this is very unexpected and it annoys me. I have function called default() in all my classes. But, I can’t call it for some reason. I guess it’s because of ‘default:’ in switch statement (which I don’t use at all).

Is this really true that I can’t name my function default() in php or am I doing something wrong?

Here’s the error:

Parse error: syntax error, unexpected T_DEFAULT, expecting T_STRING in 
C:\Users\Jinxed\Desktop\WebTrgovina\app\c\Controller.c.php on line 8

And here’s the code in question:

<?php
abstract class Controller {
    protected $view;
    function __construct() {
    }
    abstract function default();
    function getView(){
        return $this->view;
    }
}

Code works fine when I rename default to something else, but this is annoying, is there any solution to have function named default()?

  • 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-03T03:00:14+00:00Added an answer on June 3, 2026 at 3:00 am

    You cannot use a reserved word as a class function. You can, however, use __call:

    <?php
    abstract class Controller {
    
        public function _default($some, $args) {}
    
        public function __call($name, $arguments) {
            if ($name === 'default') {
                //return call_user_func_array(array($this, '_default'), $arguments); // has args
                return $this->_default(); // simpler
            }
        }
    }
    

    Which will permit you to do $foo->default(). A better idea though would be to not choose an implementation/api that relies upon using reserved words for method names.

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

Sidebar

Related Questions

I'm stuck! I have this very simple test code and I can't get it
Given this very familiar model of prototypal construction: function Rectangle(w,h) { this.width = w;
I've written this very simple function to replace a file extension using LINQ in
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I find this very strange, must be something I'm doing wrong, but still... I'm
Working on a NodeJS project, I came a across this very unexpected behaviour that
I get an unexpected T_STRING error for this very commonly used Wordpress code (loop),
I'm using the Coin Slider on my website but encountered a very unexpected surprise
I was very puzzled by some unexpected compile errors in my code recently. I
I have a very simple makefile: all: @for i in 1 2 3;\ do

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.