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;
}

}

?>









share|improve this question
























  • Formatted the code to make it readable.
    – Fabulous
    Nov 10 at 23:54















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;
}

}

?>









share|improve this question
























  • Formatted the code to make it readable.
    – Fabulous
    Nov 10 at 23:54













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;
}

}

?>









share|improve this question















<?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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Bressuire

Vorschmack

Quarantine