A
A
AlikDex2015-12-19 11:30:29
PHP
AlikDex, 2015-12-19 11:30:29

For general development: applying methods to properties?

As a student, I was fond of writing all sorts of small softins on Borland C++ 6 versions. Here, there was such an interesting style, something like:
myObject->caption.length();
What determined the length of the text of the caption element. Here. Whether it is possible to implement similar in pyhype? For example:

// Определение длины заголовка:
$myObject->title->length();

//или приведение к определенному типу:
$myObject->comments_num->int();

Or the same syntax with a dot as in c++.
What is important, this should be, as it were, native. Those. automatically apply to any class, or at least to a group of classes.
Maybe someone has examples, or thoughts about the implementation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-12-19
@AlikDex

no, and it's best not to.

mb_strlen($myObject->title);
(int) $myObject->commensNum;

and it's not "applying methods to properties" but sklar objects. There was a custom implementation, but you should only use it in code that no one will ever support except you.

A
Andrey, 2015-12-19
@VladimirAndreev

well, classes have __set and __get methods. nothing prevents storing properties as objects, which can have any methods...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question