How to copy material-name to all selected objects

I need a bit help:
When i run my script example, it says: material are not define!
How i must define the material when i want to copy the name of the material to all selected objects?

class Copy_Materialname_to_Object(bpy.types.Operator):
    """Copy Material-Name to Object-Name"""
    bl_idname = "tp_ops.copy_materialname_to_object"
    bl_label = "Copy Material-Name to Object"
    bl_options = {'REGISTER', 'UNDO'} 

    def execute(self, context):
        selected = bpy.context.selected_objects 

        for obj in selected:     

            #find material name ???
            #matname =            
            #matname =
            #for obj in matname:  
            #if matname:  
            #copy material name to all selected ???

I know there is a way, i found it once and forgot where…
Thanks for any help!


for object in context.selected_objects:
  if hasattr(object.active_material, 'name'): =

Or from the active object’s active material

for object in context.selected_objects: =