开发者

PHP oop build array

开发者 https://www.devze.com 2023-01-01 23:46 出处:网络
If I would need to build up an array with OOP based PHP, would this be the proper way to do it? class MyClass {

If I would need to build up an array with OOP based PHP, would this be the proper way to do it?

class MyClass {

    $array = array();

    function ad开发者_如何学JAVAdElement($value) {
        $this->array[] = $value;

    }

    function fetch() {

        $return = $this->memcached->getMulti($this->array);        

        return $return;
    }


}

PHP file where it will be used:

<?php

$this->myClass->addElement('key1');
$this->myClass->addElement('key1');
$this->myClass->addElement('key1');
$var = $this->myClass->fetch();


My suggestion: use SPL ArrayObject instead of implementing your own solution.


Take a look at the ArrayAccess interface

0

精彩评论

暂无评论...
验证码 换一张
取 消