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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:31:27+00:00 2026-05-14T08:31:27+00:00

Ok i have a problem, sorry if i cant explaint it clear but the

  • 0

Ok i have a problem, sorry if i cant explaint it clear but the code speaks for its self.

i have a class which generates objects from a given class name;
Say we say the class is Modules:

public function name($name)
{

   $this->includeModule($name);

   try
   {
       $module    = new ReflectionClass($name);
     $instance = $module->isInstantiable() ? $module->newInstance() : "Err";

      $this->addDelegate($instance);
   }

   catch(Exception $e)
   {
      Modules::Name("Logger")->log($e->getMessage());
   }
   return $this;
 }

The AddDelegate Method:

protected function addDelegate($delegate)
{
    $this->aDelegates[] = $delegate;
}

The __call Method

public function __call($methodName, $parameters)
{

   $delegated = false;

   foreach ($this->aDelegates as $delegate)
   {
          if(class_exists(get_class($delegate)))
          {

         if(method_exists($delegate,$methodName))
         {
        $method     = new ReflectionMethod(get_class($delegate), $methodName);

        $function   = array($delegate, $methodName);

       return  call_user_func_array($function, $parameters);
          }
     }

   }

The __get Method

public function __get($property)
    {
        foreach($this->aDelegates as $delegate)
        {
            if ($delegate->$property !== false)
            {
                return $delegate->$property;
            }

        }


    }

All this works fine expect the function __set

public function __set($property,$value)
    {

        //print_r($this->aDelegates);

        foreach($this->aDelegates as $k=>$delegate)
        {
            //print_r($k);
            //print_r($delegate);
            if (property_exists($delegate, $property))
            {
                $delegate->$property = $value;
            }

        }
        //$this->addDelegate($delegate);
        print_r($this->aDelegates);


    }

class tester
{
  public function __set($name,$value)
    {
        self::$module->name(self::$name)->__set($name,$value);
    }
}


Module::test("logger")->log("test"); //  this logs,  it works
echo Module::test("logger")->path; //prints /home/bla/test/ this is also correct

But i cant set any value to class log like this

Module::tester("logger")->path ="/home/bla/test/log/";

The path property of class logger is public so its not a problem of protected or private property access.

How can i solve this issue? I hope i could explain my problem clear.

EDIT:
A simple demonstration

Modules::Name("XML_Helper")->xmlVersion ="Hello"; // default is 333
$a =  Modules::Name("XML_Helper")->xmlVersion; // now $a should contain "Hello" 
echo $a; // prints 333

What i need is

Modules::Name("XML_Helper")->xmlVersion ="Hello"; // default is 333
$a =  Modules::Name("XML_Helper")->xmlVersion; // now $a should contain "Hello" 
echo $a; // prints Hello
  • 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-14T08:31:27+00:00Added an answer on May 14, 2026 at 8:31 am

    I realise you already said that path is public, but it’s still worth mentioning: If you’re using PHP 5.3.0+, note this quirk of property_exists():

    5.3.0 | This function checks the existence of a property independent of
    accessibility

    In other words, if you check if (property_exists($delegate, $property)), you have no guarantee you have access to $delegate->$property for writing (or reading, for that matter, but you are trying to write).

    As for actual troubleshooting: You could try checking if your if (property_exists($delegate, $property)) statement actually executes. If it doesn’t, check the case of $property.

    Sidenote: It’s fairly hard to read the code you posted up, which makes it a bit of a pain to troubleshoot. Could you edit your post and indent it properly?

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

Sidebar

Related Questions

First sorry if its a stupid question but i ran into a problem what
I have a problem writing to the SD card, here is the code: (Sorry
before everything, ty for helping and sorry for the noob question. I have problem
First, sorry for my bad english, I'm French. Here the problem : I have
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a basic problem but Google is not yielding many results for me
Hi this question or problem i have its very hard i have search and
I'm terribly sorry for the title, but describing my problem with a couple of
I'm implementing multithreaded core data downloader. I have a problem with doubling objects while
sorry if the question is too dull but I have been trying to understand

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.