1

I'm using the following function where $task is an array of TaskData instances

var_dump(array_pop($task));

// outputs when used repeatdly:
object(TaskData)[18]
  private 'id_task' => string '4' (length=1)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[22]
  private 'id_task' => string '9' (length=1)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[27]
  private 'id_task' => string '18' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[46]
  private 'id_task' => string '42' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[18]
  private 'id_task' => string '47' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[36]
  private 'id_task' => string '57' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[35]
  private 'id_task' => string '63' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[41]
  private 'id_task' => string '68' (length=2)
  private 'name' => null
  private 'process_id' => null

object(TaskData)[26]
  private 'id_task' => string '70' (length=2)
  private 'name' => null
  private 'process_id' => null

How can I access the id_task item (in the sample: '4','9','18','42')?

4

1 Answer 1

1

$task seems to be an array of TaskData instances. the member you are trying to reach is private. a read on visibility

private 'id_task'

if it were public it could be reached that way:

foreach ($task as $taskData) {
    var_dump($taskData->id_task);
}

you're perfectly right, setting a public getter for a private member is a way better idea:

public function getTaskID() {
    return $this->id_task;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I created a public function public function getTaskID() {return $this->id_task;} And it works perfectly, thanks !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.