oop - PHP Object-nested data manipulation

600

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.

QUESTION:

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.

924

Answer

Solution:

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?

Source

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.