Post by Dutch Pride Code » Mon Aug 02, 2021 5:46 am

Hi everybody,

I'm learning to develop web applications but also love to learn how to build quality OpenCart extensions. I actually have one quick question. I just figured OpenCart does not allow properties directly inside classes, as opposed to how I learned Object Oriented Programming using PHP. The question is... Why not? Am I allowed to declare properties inside methods instead? Or how exactly does this work?

Using version 3.0.3.7 on localhost
Last edited by Dutch Pride Code on Mon Aug 02, 2021 5:39 pm, edited 1 time in total.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by straightlight » Mon Aug 02, 2021 6:20 am

EMGX wrote:
Mon Aug 02, 2021 5:46 am
Hi everybody,

I'm learning to develop web applications but also love to learn how to build quality OpenCart extensions. I actually have one quick question. I just figured OpenCart does not allow properties directly inside classes, as opposed to how I learned Object Oriented Programming using PHP. The question is... Why not? Am I allowed to declare properties inside methods instead? Or how exactly does this work?

Using version 3.0.3.7 on localhost
Use command lines to search the lines for:

Code: Select all

$this->load->controller
This will save you the trouble: viewtopic.php?f=202&t=221869&p=810094#p810094 . Alternatively, you could create an extension that could call either models or library files or even by using the Event engine from the core: https://github.com/opencart/opencart/wiki/Events-System .

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by thekrotek » Mon Aug 02, 2021 1:56 pm

What do you mean? OpenCart is a generic PHP network, you can do any generic stuff.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by Dutch Pride Code » Mon Aug 02, 2021 4:41 pm

thekrotek wrote:
Mon Aug 02, 2021 1:56 pm
What do you mean? OpenCart is a generic PHP network, you can do any generic stuff.
If I were to declare a property:

Code: Select all

class ControllerClassName extends Controller {
	$property;
	
	public function methodName {
		$property = 1;
	}
}
The actual page I'm loading will give me an "Unexpected variable" message, making it impossible the way I'm doing it here. This is allowed using the 'generic' PHP you're talking about, but apparently OpenCart handles this differently.

User avatar
Active Member

Posts

Joined
Sun Jan 26, 2020 9:46 pm

Post by OSWorX » Mon Aug 02, 2021 5:10 pm

EMGX wrote:
Mon Aug 02, 2021 4:41 pm
thekrotek wrote:
Mon Aug 02, 2021 1:56 pm
What do you mean? OpenCart is a generic PHP network, you can do any generic stuff.
If I were to declare a property:

Code: Select all

class ControllerClassName extends Controller {
	$property;
	
	public function methodName {
		$property = 1;
	}
}
The actual page I'm loading will give me an "Unexpected variable" message, making it impossible the way I'm doing it here. This is allowed using the 'generic' PHP you're talking about, but apparently OpenCart handles this differently.
Guess you mean more such like that:

Code: Select all

class ControllerClassName extends Controller {
	private $property; // or public/static
	
	public function methodName(): int {
		$this->property = 1;
	}
}
.. as opposed to how I learned Object Oriented Programming using PHP ..
Hmm ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by thekrotek » Mon Aug 02, 2021 5:18 pm

EMGX wrote:
Mon Aug 02, 2021 4:41 pm

Code: Select all

class ControllerClassName extends Controller {
	$property;
	
	public function methodName {
		$property = 1;
	}
}
You're using it improperly, that's all. Please, continue to study the coding.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by OSWorX » Mon Aug 02, 2021 5:43 pm

thekrotek wrote:
Mon Aug 02, 2021 5:18 pm
EMGX wrote:
Mon Aug 02, 2021 4:41 pm

Code: Select all

class ControllerClassName extends Controller {
	$property;
	
	public function methodName {
		$property = 1;
	}
}
You're using it improperly, that's all. Please, continue to study the coding.
That's what I already wrote above ..

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: alanjones and 84 guests