class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
private $container = ['a', 'b'];
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
public function offsetUnset($offset) {
unset($this->container[$offset]);
}
public function offsetGet($offset) {
return isset($this->container[$offset]) ?
$this->container[$offset] : null;
}
public function count() {
return count($this->container);
}
public function getIterator() {
return new ArrayIterator($this->container);
}
public function serialize() {
return serialize($this->container);
}
public function unserialize($data) {
$this->container = unserialize($data);
}
public function getData() {
return $this->container;
}
}
print_r(
(array) new ArrayObject(['a', 'b'])
);
print_r(
(array) new C
);
Output:
Array
(
[0] => a
[1] => b
)
Array
(
[Ccontainer] => Array
(
[0] => a
[1] => b
)
)
Because the result is not the same?
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
private $container = ['a', 'b'];
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
public function offsetUnset($offset) {
unset($this->container[$offset]);
}
public function offsetGet($offset) {
return isset($this->container[$offset]) ?
$this->container[$offset] : null;
}
public function count() {
return count($this->container);
}
public function getIterator() {
return new ArrayIterator($this->container);
}
public function serialize() {
return serialize($this->container);
}
public function unserialize($data) {
$this->container = unserialize($data);
}
public function getData() {
return $this->container;
}
}
print_r(
(array) new ArrayObject(['a', 'b'])
);
print_r(
(array) new C
);
Output:
Array
(
[0] => a
[1] => b
)
Array
(
[Ccontainer] => Array
(
[0] => a
[1] => b
)
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one or
more values. An object can also have methods to operate on those
values. The two are not compatible.
Il 23/07/21 19:39, Jerry Stuckle ha scritto:
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
    private $container = ['a', 'b'];
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ?
$this->container[$offset] : null;
    }
    public function count() {
        return count($this->container);
    }
    public function getIterator() {
        return new ArrayIterator($this->container);
    }
    public function serialize() {
        return serialize($this->container);
    }
    public function unserialize($data) {
        $this->container = unserialize($data);
    }
    public function getData() {
        return $this->container;
    }
}
print_r(
        (array) new ArrayObject(['a', 'b'])
);
print_r(
        (array) new C
);
Output:
Array
(
    [0] => a
    [1] => b
)
Array
(
    [Ccontainer] => Array
        (
            [0] => a
            [1] => b
        )
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one or
more values. An object can also have methods to operate on those
values. The two are not compatible.
Could you tell me what these methods are?
On 24/07/2021 08.26, alex wrote:
Il 23/07/21 19:39, Jerry Stuckle ha scritto:
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
    private $container = ['a', 'b'];
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ?
$this->container[$offset] : null;
    }
    public function count() {
        return count($this->container);
    }
    public function getIterator() {
        return new ArrayIterator($this->container);
    }
    public function serialize() {
        return serialize($this->container);
    }
    public function unserialize($data) {
        $this->container = unserialize($data);
    }
    public function getData() {
        return $this->container;
    }
}
print_r(
        (array) new ArrayObject(['a', 'b'])
);
print_r(
        (array) new C
);
Output:
Array
(
    [0] => a
    [1] => b
)
Array
(
    [Ccontainer] => Array
        (
            [0] => a
            [1] => b
        )
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one or
more values. An object can also have methods to operate on those
values. The two are not compatible.
Could you tell me what these methods are?
The object can be of any type, so the whole depends on the class
definition.
for example:
class myclass {
    public $array = Array();
    public function getFirst() {
       if(sizeof($this->array) == 0)
       {
           return null;
       }
       return $this->array[1];
    }
}
this has the method getFirst.
Il 24/07/21 12:10, J.O. Aho ha scritto:
On 24/07/2021 08.26, alex wrote:
Il 23/07/21 19:39, Jerry Stuckle ha scritto:
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
    private $container = ['a', 'b'];
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ?
$this->container[$offset] : null;
    }
    public function count() {
        return count($this->container);
    }
    public function getIterator() {
        return new ArrayIterator($this->container);
    }
    public function serialize() {
        return serialize($this->container);
    }
    public function unserialize($data) {
        $this->container = unserialize($data);
    }
    public function getData() {
        return $this->container;
    }
}
print_r(
        (array) new ArrayObject(['a', 'b'])
);
print_r(
        (array) new C
);
Output:
Array
(
    [0] => a
    [1] => b
)
Array
(
    [Ccontainer] => Array
        (
            [0] => a
            [1] => b
        )
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one
or more values. An object can also have methods to operate on those
values. The two are not compatible.
Could you tell me what these methods are?
The object can be of any type, so the whole depends on the class
definition.
for example:
class myclass {
     public $array = Array();
     public function getFirst() {
        if(sizeof($this->array) == 0)
        {
            return null;
        }
        return $this->array[1];
     }
}
this has the method getFirst.
???????
So what?
On 7/24/2021 7:05 AM, alex wrote:
Il 24/07/21 12:10, J.O. Aho ha scritto:
On 24/07/2021 08.26, alex wrote:
Il 23/07/21 19:39, Jerry Stuckle ha scritto:
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
    private $container = ['a', 'b'];
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ?
$this->container[$offset] : null;
    }
    public function count() {
        return count($this->container);
    }
    public function getIterator() {
        return new ArrayIterator($this->container);
    }
    public function serialize() {
        return serialize($this->container);
    }
    public function unserialize($data) {
        $this->container = unserialize($data);
    }
    public function getData() {
        return $this->container;
    }
}
print_r(
        (array) new ArrayObject(['a', 'b'])
);
print_r(
        (array) new C
);
Output:
Array
(
    [0] => a
    [1] => b
)
Array
(
    [Ccontainer] => Array
        (
            [0] => a
            [1] => b
        )
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one
or more values. An object can also have methods to operate on
those values. The two are not compatible.
Could you tell me what these methods are?
The object can be of any type, so the whole depends on the class
definition.
for example:
class myclass {
     public $array = Array();
     public function getFirst() {
        if(sizeof($this->array) == 0)
        {
            return null;
        }
        return $this->array[1];
     }
}
this has the method getFirst.
???????
So what?
It means that the ArrayObject is a built-in type allows an object to
function as an array, as the PHP doc says. Your user-defined object contains an array but does not function as an array, as the output from print_r() shows.
Il 24/07/21 18:56, Jerry Stuckle ha scritto:
On 7/24/2021 7:05 AM, alex wrote:
Il 24/07/21 12:10, J.O. Aho ha scritto:
On 24/07/2021 08.26, alex wrote:
Il 23/07/21 19:39, Jerry Stuckle ha scritto:
On 7/23/2021 5:16 AM, alex wrote:
class C implements ArrayAccess, Countable, IteratorAggregate,
Serializable {
    private $container = ['a', 'b'];
    public function offsetSet($offset, $value) {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }
    public function offsetExists($offset) {
        return isset($this->container[$offset]);
    }
    public function offsetUnset($offset) {
        unset($this->container[$offset]);
    }
    public function offsetGet($offset) {
        return isset($this->container[$offset]) ?
$this->container[$offset] : null;
    }
    public function count() {
        return count($this->container);
    }
    public function getIterator() {
        return new ArrayIterator($this->container);
    }
    public function serialize() {
        return serialize($this->container);
    }
    public function unserialize($data) {
        $this->container = unserialize($data);
    }
    public function getData() {
        return $this->container;
    }
}
print_r(
        (array) new ArrayObject(['a', 'b'])
);
print_r(
        (array) new C
);
Output:
Array
(
    [0] => a
    [1] => b
)
Array
(
    [Ccontainer] => Array
        (
            [0] => a
            [1] => b
        )
)
Because the result is not the same?
An object is not the same as a basic type. A basic type holds one >>>>>> or more values. An object can also have methods to operate on
those values. The two are not compatible.
Could you tell me what these methods are?
The object can be of any type, so the whole depends on the class
definition.
for example:
class myclass {
     public $array = Array();
     public function getFirst() {
        if(sizeof($this->array) == 0)
        {
            return null;
        }
        return $this->array[1];
     }
}
this has the method getFirst.
???????
So what?
It means that the ArrayObject is a built-in type allows an object to
function as an array, as the PHP doc says. Your user-defined object
contains an array but does not function as an array, as the output
from print_r() shows.
So there is no way to create an object (class) that can *also* function
as an array?
You can make objects to have links to other objects (reference),
then it
would be a bit array like at the same time it can hold it's data
Il 25/07/21 11:48, J.O. Aho ha scritto:
You can make objects to have links to other objects (reference),
That is?
next = new myclass();
next->next = new myclass();
then it would be a bit array like at the same time it can hold it's data
That is?
data = "my data";
next->data = "next cell data";
Il 25/07/21 11:48, J.O. Aho ha scritto:
You can make objects to have links to other objects (reference),
That is?
setName('foobar');
getName();
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (0 / 16) |
Uptime: | 150:29:18 |
Calls: | 7,615 |
Calls today: | 3 |
Files: | 12,792 |
Messages: | 5,685,304 |
Posted today: | 2 |