appCart::__construct(): The script tried to execute a method or access a property of an incomplete object
up vote
0
down vote
favorite
<?php
namespace app;
class Cart
{
public $items = null;
public $totalqty = 0;
public $totalprice = 0;
public function __construct($oldCart){
if($oldCart){
$this->items = $oldCart->items;
$this->totalqty = $oldCart->totalqty;
$this->totalprice = $oldCart->totalprice;
}
}
public function add($item,$id){
$storedItem = ['qty'=> 0, 'price' => $item->price,'item'=>$item];
if($this->items){
if(array_key_exists($id, $this->items)){
$storedItem = $this->items[$id];
}
}
$storedItem['qty']++;
$storedItem['price'] = $item->price * $storedItem['qty'];
$this->items[$id] = $storedItem;
$this->totalqty++;
$this->totalprice+=$item->price;
}
}
?>
php
add a comment |
up vote
0
down vote
favorite
<?php
namespace app;
class Cart
{
public $items = null;
public $totalqty = 0;
public $totalprice = 0;
public function __construct($oldCart){
if($oldCart){
$this->items = $oldCart->items;
$this->totalqty = $oldCart->totalqty;
$this->totalprice = $oldCart->totalprice;
}
}
public function add($item,$id){
$storedItem = ['qty'=> 0, 'price' => $item->price,'item'=>$item];
if($this->items){
if(array_key_exists($id, $this->items)){
$storedItem = $this->items[$id];
}
}
$storedItem['qty']++;
$storedItem['price'] = $item->price * $storedItem['qty'];
$this->items[$id] = $storedItem;
$this->totalqty++;
$this->totalprice+=$item->price;
}
}
?>
php
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
<?php
namespace app;
class Cart
{
public $items = null;
public $totalqty = 0;
public $totalprice = 0;
public function __construct($oldCart){
if($oldCart){
$this->items = $oldCart->items;
$this->totalqty = $oldCart->totalqty;
$this->totalprice = $oldCart->totalprice;
}
}
public function add($item,$id){
$storedItem = ['qty'=> 0, 'price' => $item->price,'item'=>$item];
if($this->items){
if(array_key_exists($id, $this->items)){
$storedItem = $this->items[$id];
}
}
$storedItem['qty']++;
$storedItem['price'] = $item->price * $storedItem['qty'];
$this->items[$id] = $storedItem;
$this->totalqty++;
$this->totalprice+=$item->price;
}
}
?>
php
<?php
namespace app;
class Cart
{
public $items = null;
public $totalqty = 0;
public $totalprice = 0;
public function __construct($oldCart){
if($oldCart){
$this->items = $oldCart->items;
$this->totalqty = $oldCart->totalqty;
$this->totalprice = $oldCart->totalprice;
}
}
public function add($item,$id){
$storedItem = ['qty'=> 0, 'price' => $item->price,'item'=>$item];
if($this->items){
if(array_key_exists($id, $this->items)){
$storedItem = $this->items[$id];
}
}
$storedItem['qty']++;
$storedItem['price'] = $item->price * $storedItem['qty'];
$this->items[$id] = $storedItem;
$this->totalqty++;
$this->totalprice+=$item->price;
}
}
?>
php
php
edited Nov 10 at 23:54
Fabulous
2,00611121
2,00611121
asked Nov 10 at 20:52
sharif khan
12
12
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54
add a comment |
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
draft saved
draft discarded
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243298%2fapp-cart-construct-the-script-tried-to-execute-a-method-or-access-a-proper%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Formatted the code to make it readable.
– Fabulous
Nov 10 at 23:54