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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:28:31+00:00 2026-05-25T12:28:31+00:00

This one really messes with my head: Whenever I try to typecast a var

  • 0

This one really messes with my head:

Whenever I try to typecast a var passed to a function of type ‘string’, like this:

public function __call( string $name , array $args ) {
    ...
}

I get the following error:

Catchable fatal error: Argument 1 passed to [ClassName]::__call() must
be an instance of string, string given in [php_file_name] on line
[line_number]

Huh? “Must be an instance of string, string given”? Did I not pass a string? I seriously don’t understand this error message.

Now my solution has always been something like:

public function __call( $name , array $args ) {
    if (!is_string($name)) { throw new Exception('$name must be a string');
}

However, my question, is there a way to actually typecast it in the method definition rather than inside the method itself?

  • 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-05-25T12:28:32+00:00Added an answer on May 25, 2026 at 12:28 pm

    In php you can force functions parameters to be either an array or an object (type hinting). So your action is only accepting “string” objects for the first argument, not variables of type string.

    Type Hints can only be of the object and array (since PHP 5.1) type. Traditional type hinting with int and string isn’t supported.

    More info here: http://www.php.net/manual/en/language.oop5.typehinting.php

    And to answer your question: Normally, you can’t!

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

Sidebar

Related Questions

I'm not really sure how to google this one . I would like to
this one is really easy. I'm trying to create a Regular Expression that will
Boy, this one is really weird. I expect the following code to print 1990,
Ok, this one is really weird... I can't show code for it exactly cause
Probably a really simple one this - I'm starting out with C# and need
I'm really frustrated with this one. A few weeks ago I got it working
I'm really stumped by this one! The StackFrame object ( MSDN Link ) has
I really need help on this one. I am having a simple login form
Really ripping my hair out on this one. I have a JAAS Authentication Provider
Hey, I'm really struggling with this one. I'am trying to port a small piece

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.