Skip to content

Commit

Permalink
use of get_Item/set_Item as in array access
Browse files Browse the repository at this point in the history
- allows to use Dictionary as array (again)
  • Loading branch information
jakubmisek committed Dec 6, 2020
1 parent 1eb7ccf commit 65e01e3
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Peachpie.Runtime/Reflection/TypeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,24 +87,26 @@ internal TypeMethods(PhpTypeInfo type)
// ignore methods in base classes that has been "overriden" in current class
// in PHP we do override even if signature does not match (e.g. __construct)
SelectVisibleOverrides(ref overrides);

// TODO: negative {index} in case of non-user method

var info = PhpMethodInfo.Create(++index, m.Key, overrides, type);

MagicMethods magic;
var magic = MagicMethods.undefined;

if (IsSpecialName(overrides))
{
// 'specialname' methods,
// get_Item, set_Item
Enum.TryParse<MagicMethods>(m.Key.ToLowerInvariant(), out magic);
if (!Enum.TryParse<MagicMethods>(m.Key.ToLowerInvariant(), out magic))
{
continue;
}
}
else
{
if (_methods == null)
_methods = new Dictionary<string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);

// TODO: negative {index} in case of non-user method

var info = PhpMethodInfo.Create(++index, m.Key, overrides, type);

if (magic == MagicMethods.undefined)
{
_methods ??= new Dictionary<string, PhpMethodInfo>(StringComparer.OrdinalIgnoreCase);
_methods[info.Name] = info;

// resolve magic methods
Expand All @@ -113,9 +115,7 @@ internal TypeMethods(PhpTypeInfo type)

if (magic != MagicMethods.undefined)
{
if (_magicMethods == null)
_magicMethods = new Dictionary<MagicMethods, PhpMethodInfo>();

_magicMethods ??= new Dictionary<MagicMethods, PhpMethodInfo>();
_magicMethods[magic] = info;
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ MagicMethods MagicMethodByName(string name)
return
access != MethodAttributes.Assembly &&
access != MethodAttributes.FamANDAssem &&
!m.IsSpecialName &&
// !m.IsSpecialName && // we need to handle get_item/set_item but not remember it in type's runtime methods tho
!IsSpecialHidden(m) &&
!ReflectionUtils.IsPhpHidden(m);
};
Expand Down

0 comments on commit 65e01e3

Please sign in to comment.