oop - PHP Object-nested data manipulation


I have two classes,A andB, that work together, like this:

  • Global scope instantiateAobject.
  • Aobject instantiateBobject as a public property.
  • Bobject containsCarray as a public property.


How do I manipulateCarray from global scope, without copying it, AND without explicitly pointing atA->B->C for each operation?

PS: This is a minimal example. My chains could end up rather long, if no solution exists.




Use a reference. You will have to use A->B->C only once per scope.

$c = &$A->b->c;
$c['something'] = 'somethiing else';

People are also looking for solutions to the problem: php - How to Rewrite engine for form submission?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.