Can’t use method return value in write context – php Error

Can’t use method return value in write context – php Error

Yup, just to share – as usual.
While working on one of my projects I run this error. Here is the snippet where the error occurs:

....
        $carPrice = $this->getCarPrice(); // this would return object of CarPrice
        if (empty($carPrice->getCarPriceId()))
        {.....

Where $carPrice is an object to be returned after passing an array of data ($new_price) to the controller.
And on the next line, I was trying to if priceId of the car is not empty.
The problem is caused on the second operand of the if statement (empty($carPrice->getCarPriceId()) –
Here is how I get fool around..

...
$car_price_id = $carPrice->getCarPriceId();
if (empty($car_price_id))
{
...

It happens that function empty() [and even isset() ] do expect a variable to be checked otherwise, parse error will happen.

See how you would solve these known algorithm problems

binary tree problems with solution

Find the first occurence of number in the sorted array

Get maximum occurring character

find longest word in the sentence

Implementing tokenizer and adding tokens to the linked list

Find the pairs that makes K Complementary in the given array java solution

Implement Queue Using two Stacks – JavaScript algorithm

Java solution for checking anagram strings – tell if phrases are anagrams

Check if two strings are anagrams or not

Kadane’s algorithm in C – Dynamic Programming

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*