Cannot Instantiate Class In Php 5.4

Hi,

Im a newbie , this is my first post. I created a custom class named "BlindsPrices" and instantiated it like this :


$blindPrice = new BlindsPrices;

My Yii version is : yii-1.1.13 . This code works fine on my localhost (PHP 5.3 XAMPP server) . But when i hosted it on a server (PHP 5.4 Linux) the lines after the above code doest not run. Can someone please help me with this issue. Sine it runs on my local machine i have no dea why this simple code would not run on server.

Some additional info :

"BlindsPrices" class does not have any database tables associated with it. Its just an independant class which has some common functions. And im able to use the Model classes generated by Yii without any issues.

Thanks

Need more info.

What’s the error, how the class looks like and so on.

The class im trying to initiate is :


<?php 


/*

 * This class is used to calculate the Price of the blind based on Width & Height of the blind.

*/

class BlindsPrices  {


	/*

	 * Gets the price for the given "WIDTH" & "DROP"

	*

	* $blind_type - can be any one of the following :

	* 1. aluminiumvenetianblinds

	* 2. evolutionvenetianblinds

	* 3. verticalblinds

	* 4. woodenvenetianblinds

	*

	*/


	public function getPrice($WIDTH, $DROP, $blind_type ,$product_type_id) {

		$WIDTH = $this->getWidth($WIDTH, $blind_type , $product_type_id);

		$DROP = $this->getDrop($DROP, $blind_type , $product_type_id);

		$Criteria = new CDbCriteria();

		$Criteria->condition = "blind_width = $WIDTH AND blind_drop = $DROP AND product_type_id = $product_type_id";


		//Get the price model for given blind type

		$priceModel = $this->getPriceModelForBlindType($blind_type);


		$model = $priceModel::model()->find($Criteria);

		return $model->price;

	}


	/*

	 * The width is rounded to nearest (upper) 100

	* That value is looked up in the database

	*

	* Steps to do that:

	* 1. Get all "width" values for the product from DB

	* 2. Add it to array

	* 3. Add customer entered value to array

	* 4. Find the next highest number to customer entered number

	*/


	public function getWidth($WIDTH = 0, $blind_type , $product_type_id) {

		// Get Database name for Blind Type

		$databaseName = $this->getDatabaseNameForBlindType($blind_type);

		$distinct_width_array = Yii::app()->db->createCommand(array(

				'select' => 'blind_width',

				'where' => 'product_type_id = '.$product_type_id,

				'distinct' => 'true',

				'from' => $databaseName,

		))->queryColumn();

		array_push($distinct_width_array, $WIDTH);

		// Remove values less than 'customer entered width'

		for ($index = 0; $index < count($distinct_width_array); $index++) {

			if ($WIDTH > $distinct_width_array[$index]) {

				unset($distinct_width_array[$index]);

			}

		}

		// Sort ascending

		asort($distinct_width_array);

		// Re-arrange the array index from 0

		$distinct_width_array = array_values($distinct_width_array);


		return $distinct_width_array[1];

	}


	/*

	 *

	* The DROP is rounded to nearest (upper) 100

	* That value is looked up in the database

	*

	* Steps to do that:

	* 1. Get all "DROP" values for the product from DB

	* 2. Add it to array

	* 3. Add customer entered value to array

	* 4. Find the next highest number to customer entered number

	*/


	public function getDrop($DROP = 0, $blind_type , $product_type_id) {

		// Get Database name for Blind Type

		$databaseName = $this->getDatabaseNameForBlindType($blind_type);


		$distinct_drop_array = Yii::app()->db->createCommand(array(

				'select' => 'blind_drop',

				'where' => 'product_type_id = '.$product_type_id,

				'distinct' => 'true',

				'from' => $databaseName,

		))->queryColumn();

		array_push($distinct_drop_array, $DROP);

		// Remove values less than 'customer entered drop'

		for ($index = 0; $index < count($distinct_drop_array); $index++) {

			if ($DROP > $distinct_drop_array[$index]) {

				unset($distinct_drop_array[$index]);

			}

		}

		// Sort ascending

		asort($distinct_drop_array);

		// Re-arrange the array index from 0

		$distinct_drop_array = array_values($distinct_drop_array);


		return $distinct_drop_array[1];

	}


	/*

	 * Returns the relavent prices model for the blind type

	*/

	public function getPriceModelForBlindType($blindType){

		if($blindType == "aluminiumvenetianblinds"){

			return "AluminiumVenetianBlindsPrices";

		} else if($blindType == "evolutionvenetianblinds"){

			return "EvolutionVenetianBlindsPrices";

		} else if($blindType == "verticalblinds"){

			return "VerticalBlindsPrices";

		} else if($blindType == "woodenvenetianblinds"){

			return "WoodenVenetianBlindsPrices";

		}

	}


	/*

	 * Returns the relavent Database name for the blind type

	*/

	public function getDatabaseNameForBlindType($blindType){

		if($blindType == "aluminiumvenetianblinds"){

			return "aluminium_venetian_blinds_prices";

		} else if($blindType == "evolutionvenetianblinds"){

			return "evolution_venetian_blinds_prices";

		} else if($blindType == "verticalblinds"){

			return "vertical_blinds_prices";

		} else if($blindType == "woodenvenetianblinds"){

			return "wooden_venetian_blinds_prices";

		}

	}


	/*

	 * Get total Aluminiumvenetianblinds price.

	* (After saving all the prices to database)

	* Total price = Width drop price + spring pins price + accessories price

	*/

	public function getAluminiumvenetianblindsTotalPrice($pk = 0){

		$SQL = "SELECT sum(totalprice) as total FROM (


		SELECT sum(`aluminium_venetian_blinds`.`width_drop_price` + `aluminium_venetian_blinds`.`spring_pins_price`) AS totalprice FROM `aluminium_venetian_blinds`

		WHERE `aluminium_venetian_blinds`.`id` = $pk


		UNION ALL


		SELECT sum(`accessories_quotation`.`price` * `accessories_quotation`.`quantity`) AS totalprice FROM `accessories_quotation` WHERE

		`accessories_quotation`.`product_id` = $pk AND `accessories_quotation`.`accessory_type` = 'aluminium_venetian_blinds'


		) A";

		$connection = Yii::app()->db;

		$command = $connection->createCommand($SQL);

		$row = $command->queryRow();

		if(count($row['total'])==0){

			$row = 0;

		} else {

			$row = $row['total'];

		}

		return $row;

	}


	/*

	 * Get total Evolution venetian blinds price.

	* (After saving all the prices to database)

	* Total price = Width drop price + spring pins price + accessories price

	*/

	public function getEvolutionvenetianblindsTotalPrice($pk = 0){

		$SQL = "SELECT sum(totalprice) as total FROM (


		SELECT sum(`evolution_venetian_blinds`.`width_drop_price` + `evolution_venetian_blinds`.`spring_pins_price`) AS totalprice FROM `evolution_venetian_blinds`

		WHERE `evolution_venetian_blinds`.`id` = $pk


		UNION ALL


		SELECT sum(`accessories_quotation`.`price` * `accessories_quotation`.`quantity`) AS totalprice FROM `accessories_quotation` WHERE

		`accessories_quotation`.`product_id` = $pk AND `accessories_quotation`.`accessory_type` = 'evolution_venetian_blinds'


		) A";

		$connection = Yii::app()->db;

		$command = $connection->createCommand($SQL);

		$row = $command->queryRow();

		if(count($row['total'])==0){

			$row = 0;

		} else {

			$row = $row['total'];

		}

		return $row;

	}


	/*

	 * Get total Evolution venetian blinds price.

	* (After saving all the prices to database)

	* Total price = Width drop price + spring pins price + accessories price

	*/

	public function getVerticalblindsTotalPrice($pk = 0){

		$SQL = "SELECT sum(totalprice) as total FROM (


		SELECT sum(`vertical_blinds`.`width_drop_price` + `vertical_blinds`.`spring_pins_price`) AS totalprice FROM `vertical_blinds`

		WHERE `vertical_blinds`.`id` = $pk


		UNION ALL


		SELECT sum(`accessories_quotation`.`price` * `accessories_quotation`.`quantity`) AS totalprice FROM `accessories_quotation` WHERE

		`accessories_quotation`.`product_id` = $pk AND `accessories_quotation`.`accessory_type` = 'vertical_blinds'


		) A";

		$connection = Yii::app()->db;

		$command = $connection->createCommand($SQL);

		$row = $command->queryRow();

		if(count($row['total'])==0){

			$row = 0;

		} else {

			$row = $row['total'];

		}

		return $row;

	}


	/*

	 * Get total Wooden venetian blinds price.

	* (After saving all the prices to database)

	* Total price = Width drop price + spring pins price + accessories price

	*/

	public function getWoodenvenetianblindsTotalPrice($pk = 0){

		$SQL = "SELECT sum(totalprice) as total FROM (


		SELECT sum(`wooden_venetian_blinds`.`width_drop_price` + `wooden_venetian_blinds`.`spring_pins_price`) AS totalprice FROM `wooden_venetian_blinds`

		WHERE `wooden_venetian_blinds`.`id` = $pk


		UNION ALL


		SELECT sum(`accessories_quotation`.`price` * `accessories_quotation`.`quantity`) AS totalprice FROM `accessories_quotation` WHERE

		`accessories_quotation`.`product_id` = $pk AND `accessories_quotation`.`accessory_type` = 'vertical_blinds'


		) A";

		$connection = Yii::app()->db;

		$command = $connection->createCommand($SQL);

		$row = $command->queryRow();

		if(count($row['total'])==0){

			$row = 0;

		} else {

			$row = $row['total'];

		}

		return $row;

	}

	

	public function getTotalPriceForQuotation(){

		

	}


}


?>

its inside protected/models folder.

im trying to initiate it from a controller like this :


$blindPrice = new BlindsPrices;

there’s no complaint about file not found error. Actually theres no error at all. its just that lines after this code is not executed.

Hi

create a constructor add echo ‘hi contructor here!’;

what is the result both localhost and online ?

Hi,

Echo works on localhost, not online .

add into the main index.php of your project on top of code


ini_set('display_errors','On');

error_reporting(E_ALL);



Αny error ?

Thanks for this. I totally relied on Yii logs. It didnt show any useful errors. But the above code did. I was able to fix the isue :slight_smile:

So, what was the problem ?

It is useful for the other Yii members to know :)