• You are not logged in. | Login

Post a reply

March 16, 2007 12:47 pm

Keeper
Member
Ranks

Indicating the type of variables

Where can I read about how to indicate the type of variable which is transmitted to the function, for example

function myFunction(varType $myVar) {

}

Here varType is the type of variable. This works with array and how to indicate other types of variables, for instance, strings, whole number, with floating dot and so on.

Analogically to array I try

public function editClientGetDataFromSQL(integer $id) {

if (!$module->editClientGetDataFromSQL((int)$uriParams["client"])) ...

Returns error:
Catchable fatal error: Argument 1 passed to clients::editClientGetDataFromSQL() must be an instance of integer, integer given, called in D:\Web\www\portal.localhost\htdocs\modules\clients\admin.php on line 45 and defined in D:\Web\www\portal.localhost\htdocs\modules\clients\__classes.php on line 1

At the same time construction

public function editClientGetDataFromSQL(array $id) {

if (!$module->editClientGetDataFromSQL(array($uriParams["client"]))) ...
works correctly

PHP 5.2.1
WIN XP


 

 

March 16, 2007 12:52 pm

sam43inwood
Member
Ranks

Re: Indicating the type of variables

Who told you that it is possible even with array or someObject?? Where is it written? Could you send me a link to the manual, please!


 

 

March 16, 2007 12:55 pm

Conker
Member
Ranks

Re: Indicating the type of variables


 

 

March 16, 2007 1:00 pm

Keeper
Member
Ranks

Re: Indicating the type of variables

Thanks. I have been searching but I couldn’t find anything for a long time.

I was totally disappointed with

Traditional type hinting with int and string isn't supported.

Who knows if support for int, float, string is planned?
As for me, from the code’s security point of view it would be good to indicate type of the variable which we are expecting in the function (for example, for the very unique ID which is integer) especially when the work is done within team and someone has forgotten to reduce the type and if we indicate in the function it will result into fatal error.


 

 

March 16, 2007 1:03 pm

jjjlc1983
Member
Ranks

Re: Indicating the type of variables

if we indicate in the function it will result into fatal error.

Isn’t it too strict?
So semantics of 7 and "7" in PHP is nearly equal.
If you like it or not – that is a separate question but the fact remains.
And making everyone always write $obj->method((int) $id, (bool) $flag) isn’t good either.
When you need reduction of the type it should be declared in the function itself.

P.S. By the way, realization of some checkFuncArgs('lsb'); is rather simple.


 

 

March 16, 2007 1:16 pm

Keeper
Member
Ranks

Re: Indicating the type of variables

jjjlc1983
Nearly in all programming languages beginning from quick basic 88 the ability to indicate the type of variable is introduced (in some languages it is necessary).

Isn’t it too strict?

What do you mean with ‘strict’? Indicating the type of variable we need?

On the other hand, for instance, 5 persons take part in the software development in PHP. Each of them is occupied with development of definite classes, modules and so on.
Finally they will be composed into one big product. I.e. the whole work will be handed over to one or two web-programmers who will need to bring this all together.
You should agree that everyone writes in ‘his own style’, can make errors or will hope that the data will be checked in the main module of this software or by someone in advance or forgets about types reducing at all relying on that ‘semantics of 7 and "7" in PHP is nearly equal’ or something else…

(7 and "7" are equal at first sight but they are different inside and so the product can be broken and all the work will be ‘vain’ because of one type that hasn’t been reduced).

Last edited by Keeper (March 16, 2007 1:17 pm)


 

 

March 16, 2007 1:23 pm

biopd42
Member
Ranks

Re: Indicating the type of variables

Keeper, your ponderings are rather theoretical…PHP is a language without strict typification. If you need types, you are to use Java or Python.  wink


 

 

March 16, 2007 1:27 pm

jjjlc1983
Member
Ranks

Re: Indicating the type of variables

and so the product can be broken down

Give an example.
Error may have different consequences. I would even say that for each error it’s possible to develop such a code in which it will be fatal.

or will hope that the data will be checked in the main module

Sure, security (and to tell more precisely – correctness) should be provided beginning from the lowest level.


 

 

March 16, 2007 1:30 pm

purplebean
Member
Ranks

Re: Indicating the type of variables

Keeper, you are to use С/C++ but if you aren’t skilled enough, typification won’t help you. It’s enough to reduce variables to necessary types and check them.

If you add types to PHP you will be about to get C.


 

 

March 16, 2007 1:34 pm

sirburpsalot
Member
Ranks

Re: Indicating the type of variables

Keeper, your ponderings are rather theoretical…PHP is a language without strict typification. If you need types, you are to use Java or Python.

As I can see, you are also fond of theory.
If you mean static typification, Python has the dynamic one  wink


 

 

March 16, 2007 1:38 pm

biopd42
Member
Ranks

Re: Indicating the type of variables

sirburpsalot, why are you talking about dynamic typification?


 

 

March 16, 2007 2:00 pm

sirburpsalot
Member
Ranks

Re: Indicating the type of variables

What do mean when talking about ‘strict typification’?


 

 

March 16, 2007 2:03 pm

Keeper
Member
Ranks

Re: Indicating the type of variables

I didn’t speak about obligation, just about ability.
If you’ve made array and someObj why don’t you make int, string?
If someone needs it he will use it.


 

 
  • Actions
  • Top
ITCrimea. Ukraine Web Development Company. Professional Developers and Web Designers Team
Custom Web Designs, Internet Applications, E-Commerce Websites, Interactive Sites, Database-Driven Sites and Services