Jump to content

Type Safety In Php


rstoll

Recommended Posts

Hi,

 

I am currently working on my final project of my undergraduate study and the project is about type safety in PHP. One aspect of the project examines the opinion of the PHP community on this topic.

 

I now need your help. I would be very glad, if you could take 5 – 20 minutes to fill in my online survey: http://www.q-set.co.uk/q-set.php?sCode=PGSKQCJUWZVK

 

I will publish the deliverables of my project under an open source license. Thus you contribute automatically to an open source project if you fill in the form :)

 

Thanks for your help

Robert Stoll

Link to comment
https://forums.phpfreaks.com/topic/271840-type-safety-in-php/
Share on other sites

Parameters - which improvement towards type safety should be made?

[ ] A type for each parameter has to be defined in all functions/methods

[ ] A type for each parameter has to be defined in public and protected functions/methods

[ ] A type for each parameter has to be defined in public functions/methods

[ ] None of the above mentioned

[ ] I do not know

Why does this one not have an "optional" answer, but the others on the same page do?

 

Object Initialiser as in C#
$person = new Person(){Firstname='Robert',Lastname='Stoll'};
//Instead of
$person = new Person();
$person->setFirstname('Robert');
$person->setLastname('Stoll');

Forgive my ignorance, but isn't that what a constructor is for?

 

Anyways, I agree with Maq. Interesting project, will be cool to see the results.

Link to comment
https://forums.phpfreaks.com/topic/271840-type-safety-in-php/#findComment-1398630
Share on other sites

 

Why does this one not have an "optional" answer, but the others on the same page do?

 

Object Initialiser as in C#
$person = new Person(){Firstname='Robert',Lastname='Stoll'};
//Instead of
$person = new Person();
$person->setFirstname('Robert');
$person->setLastname('Stoll');

Forgive my ignorance, but isn't that what a constructor is for?

 

Object initializers are used to populate anonymous types. Anonymous types are types that don't have an actual class definition (thus no parameterized constructor). Instead, they're generated on the fly, usually as the result of some LINQ query. Example:

 

var productInfo =
   from p in products
   select new { p.ProductName, p.UnitPrice };

 

productInfo contains a collection of objects of an anonymous type that are made up of the product's name and price. That info can then be iterated over by a foreach:

 

foreach (var prod in productInfo)
{
   Console.WriteLine("Name: {0} , price: {1}", prod.ProductName, prod.UnitPrice);
}

Link to comment
https://forums.phpfreaks.com/topic/271840-type-safety-in-php/#findComment-1398749
Share on other sites

Also..

 

(3) Parameters - which improvement towards type safety should be made?

    A type for each parameter has to be defined in all functions/methods

    A type for each parameter has to be defined in public and protected functions/methods

    A type for each parameter has to be defined in public functions/methods

    None of the above mentioned

    I do not know

 

Shouldn't there be an option to optionally define a type for each parameter, like in #4? Forcing a type is going to break about 99% of PHP scripts out there.

Link to comment
https://forums.phpfreaks.com/topic/271840-type-safety-in-php/#findComment-1398751
Share on other sites

  • 11 months later...
Heya,

 

Quite a long time ago (almost a year), I asked you guys to fill in a survey about type safety in PHP which I conducted in context of my bachelor thesis.

Unfortunately, I did not really have time to publish all results on a website so far but I am happy to announce that you can find the results here now:


 

My bachelor thesis serves as a basis of the open source project TSPHP. You can find further information about it on the wiki as well:


 

Please don't hesitate if you have further questions about the survey or the project.

 

Cheers,

Robert

Link to comment
https://forums.phpfreaks.com/topic/271840-type-safety-in-php/#findComment-1460631
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.