0

What would be an efficient and secure way to make an inner class in PHP? I have seen solutions such as in here Nested or Inner Class in PHP but using this type of check in an algorithm would be a lot of processing for every node of an algorithm function.

I have been playing around with certain algorithms in PHP, and this seems to be a big compromise when creating the algorithms in PHP. I can make the node class have all variables as public but that is never an ideal way to go. I haven't seen too many PHP algorithm examples and am starting to wonder if people just don't build them in PHP because of compromises like this?

Community
  • 1
  • 1
vancouverwill
  • 128
  • 1
  • 11

2 Answers2

0

How about using the standard library which provides interfaces to implement the above?

SplQueue, SplStack and an SplHeap is a pretty close representation of a tree.

It's tough to comment on efficient and secure without more context, however the security of classes is still your responsibility and the visibility keywords can assist you with that.

Martin
  • 6,632
  • 4
  • 25
  • 28
  • thanks, I was hoping to use my own implementations as have more flexibility but extending those Spl classes may be the smartest way to go while sticking with PHP – vancouverwill Feb 03 '14 at 19:16
0

As mentioned in Nested or Inner Class in PHP, using nested classes isn't possible with PHP.

PHP uses namespaces for organization as Java do with packages. But for encapsulation there is no such construct in PHP as it wasn't necessary.

Node traversal algorithms and such use Node objects with getters or public properties and composition.

Community
  • 1
  • 1
Michal Brašna
  • 2,293
  • 13
  • 17