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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:08:58+00:00 2026-06-12T01:08:58+00:00

I have a problem with a magic method __set() in an abstract class (Model),

  • 0

I have a problem with a magic method __set() in an abstract class (Model), as i cant assign any property of the class that extend Model. Neither trying to print the name of the variable in the __set method:

abstract class Model
{
public $data;
public function __set($name, $value)
{
echo $name; $this->$name = $value;
}
}

class User extends Model
{
public $id;
}

$u = new User();
$u->data = "hello"; //print "data";
$u->id = 123; //print NOTHING.. WHY¿?
  • 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-12T01:08:59+00:00Added an answer on June 12, 2026 at 1:08 am

    __set is called when you try to assign a value in undefined property. In your case __set will never be called because both of the properties are defined and exists.

    See here the output is nothing for both of the properties and try with removing one of the property declaration part and see the output difference.

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

Sidebar

Related Questions

I have a class that uses magic methods to store properties. Here is a
I have a base class that has a method that gets executed by derived
I have a problem with magic method __call The following code works well, except
I have a problem with JavaScript magic. When I execute this code: var page
I frequently write C# code that has to use magic strings to express property
I have a problem that has been spoiling the way I want to do
I have a method that has a parameter of type DateTime that must not
I have a collection model. I succesfully created a _collection.html.erb that i call with
I have custom db class which extends MySQLi class MySQLi->query() method returns obejct with
I have a model, let's say Attachments, that uses attachment_fu to accept file uploads

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.